<?php
namespace WTC_CHECKOUT\Modules\Forms\Services;
defined('ABSPATH') || exit;
class OrderDisplayService {
    public function __construct() {
        add_action('woocommerce_admin_order_data_after_billing_address', array($this, 'display_admin_order_custom_fields'), 10, 1);
        add_action('woocommerce_order_details_after_customer_details', array($this, 'display_frontend_order_custom_fields'), 10, 1);
    }
    public function display_admin_order_custom_fields($order) {
        if (!$order) return;
        $invoice_type = $order->get_meta('_billing_invoice_type');
        echo '<div class="address">';
        echo '<h3>' . esc_html__('Fatura Bilgileri', 'wtc-checkout') . '</h3>';
        echo '<p><strong>' . esc_html__('Fatura Tipi:', 'wtc-checkout') . '</strong> ' . 
             ($invoice_type === 'corporate' ? esc_html__('Kurumsal', 'wtc-checkout') : esc_html__('Bireysel', 'wtc-checkout')) . 
             '</p>';
        if ($invoice_type === 'individual') {
            $tckn = $order->get_meta('_billing_tckn');
            if ($tckn) {
                echo '<p><strong>' . esc_html__('TC Kimlik No:', 'wtc-checkout') . '</strong> ' . esc_html($tckn) . '</p>';
            }
        } else {
            $tax_number = $order->get_meta('_billing_tax_number');
            $tax_office = $order->get_meta('_billing_tax_office');
            if ($tax_number) {
                echo '<p><strong>' . esc_html__('Vergi No:', 'wtc-checkout') . '</strong> ' . esc_html($tax_number) . '</p>';
            }
            if ($tax_office) {
                echo '<p><strong>' . esc_html__('Vergi Dairesi:', 'wtc-checkout') . '</strong> ' . esc_html($tax_office) . '</p>';
            }
        }
        echo '</div>';
    }
    public function display_frontend_order_custom_fields($order) {
        if (!$order) return;
        $invoice_type = $order->get_meta('_billing_invoice_type');
        echo '<section class="woocommerce-customer-details">';
        echo '<h2 class="woocommerce-column__title">' . esc_html__('Fatura Bilgileri', 'wtc-checkout') . '</h2>';
        echo '<table class="woocommerce-table shop_table custom_details">';
        echo '<tr>';
        echo '<th>' . esc_html__('Fatura Tipi', 'wtc-checkout') . ':</th>';
        echo '<td>' . ($invoice_type === 'corporate' ? esc_html__('Kurumsal', 'wtc-checkout') : esc_html__('Bireysel', 'wtc-checkout')) . '</td>';
        echo '</tr>';
        if ($invoice_type === 'individual') {
            $tckn = $order->get_meta('_billing_tckn');
            if ($tckn) {
                echo '<tr>';
                echo '<th>' . esc_html__('TC Kimlik No', 'wtc-checkout') . ':</th>';
                echo '<td>' . esc_html($tckn) . '</td>';
                echo '</tr>';
            }
        } else {
            $tax_number = $order->get_meta('_billing_tax_number');
            $tax_office = $order->get_meta('_billing_tax_office');
            if ($tax_number) {
                echo '<tr>';
                echo '<th>' . esc_html__('Vergi No', 'wtc-checkout') . ':</th>';
                echo '<td>' . esc_html($tax_number) . '</td>';
                echo '</tr>';
            }
            if ($tax_office) {
                echo '<tr>';
                echo '<th>' . esc_html__('Vergi Dairesi', 'wtc-checkout') . ':</th>';
                echo '<td>' . esc_html($tax_office) . '</td>';
                echo '</tr>';
            }
        }
        echo '</table>';
        echo '</section>';
    }
} 