<?php
namespace WTC_CHECKOUT\Modules\SMS\Admin;
defined('ABSPATH') || exit;
class SMSSettings {
    private $tabs = [];
    private $active_tab = '';
    private $sms_nonce_name = 'wtc_sms_settings_nonce';
    private $test_sms_nonce_name = 'wtc_sms_test_nonce';
    public function __construct() {
        $this->tabs = [
            'settings' => 'Ayarlar',
            'templates' => 'SMS Şablonları',
            'logs' => 'SMS Kayıtları',
        ];
    }
    public function load_translations() {
        $this->tabs = [
            'settings' => __('Ayarlar', 'wtc-checkout'),
            'templates' => __('SMS Şablonları', 'wtc-checkout'),
            'logs' => __('SMS Kayıtları', 'wtc-checkout'),
        ];
    }
    public function render_settings_page() {
        $tab = isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : '';
        $nonce = isset($_GET['wtc_tab_nonce']) ? sanitize_text_field(wp_unslash($_GET['wtc_tab_nonce'])) : '';
        if ($tab && $nonce && wp_verify_nonce($nonce, 'wtc_sms_tab_action') && (array_key_exists($tab, $this->tabs) || $tab === 'admin_wtc')) {
            $this->active_tab = $tab;
            if ($tab === 'admin_wtc' && !isset($this->tabs['admin_wtc'])) {
                $this->tabs['admin_wtc'] = 'Admin WTC';
            }
        } else {
            $this->active_tab = 'settings';
        }
        echo '<div class="wrap wtc-admin-page">';
        echo '<h1>' . esc_html__('SMS Gönderimi', 'wtc-checkout') . '</h1>';
        $this->render_tabs();
        echo '<div class="wtc-card">';
        switch ($this->active_tab) {
            case 'settings':
                $this->render_sms_settings();
                break;
            case 'templates':
                $this->render_sms_templates();
                break;
            case 'logs':
                $this->render_sms_logs_tab();
                break;
            case 'admin_wtc':
                $this->render_admin_wtc();
                break;
        }
        echo '</div>'; 
        echo '</div>'; 
    }
    private function render_tabs() {
        echo '<h2 class="wtc-nav-tab-wrapper nav-tab-wrapper">';
        $nonce = wp_create_nonce('wtc_sms_tab_action');
        foreach ($this->tabs as $tab_id => $tab_name) {
            $active_class = $this->active_tab === $tab_id ? ' nav-tab-active wtc-nav-tab-active' : '';
            $url = admin_url('admin.php?page=wtc-sms&tab=' . $tab_id . '&wtc_tab_nonce=' . $nonce);
            echo '<a href="' . esc_url($url) . '" class="wtc-nav-tab nav-tab' . esc_attr($active_class) . '">' . esc_html($tab_name) . '</a>';
        }
echo '<style>
        .wtc-nav-tab-wrapper {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        gap: 10px;
        position: relative;
    }
    .wtc-right-tabs {
        margin-left: auto;
        display: flex;
        gap: 10px;
    }
    .wtc-right-tabs a {
        display: inline-flex;
        align-items: center;
        font-weight: bold;
        border-radius: 4px;
        text-decoration: none;
        padding: 10px 20px;
        transition: background-color 0.3s ease;
        font-size: 16px;
    }
    .wtc-premium-link {
        background-color: #0AA000;
        color: #fff !important;
    }
    .wtc-premium-link:hover {
        background-color:rgb(8, 97, 2);
    }
    .wtc-support-link {
        background-color: #FFDD00;
        color: #000 !important;
    }
    .wtc-support-link:hover {
        background-color: #f2cc00;
    }
    </style>';
echo '<span class="wtc-right-tabs">';
echo '<a href="https://www.woosoft.com.tr" target="_blank" class="wtc-premium-link">⭐&nbsp;&nbsp;Premium</a>';
echo '<a href="https://coff.ee/woosoft" target="_blank" class="wtc-support-link">☕&nbsp;&nbsp;Buy me a coffee</a>';
echo '</span>';
        echo '</h2>';
    }
    private function render_sms_templates() { ?>
    <div class="wtc-sms-templates-wrapper">
        <div class="wtc-sms-templates-list">
            <h3>Mevcut SMS Şablonları</h3>
            <ul id="sms-templates-list">
                <li class="wtc-template-item wtc-template-active" data-template-id="default_pending_68eabc7da4382">
                    <div class="wtc-template-info"><span class="template-name">Sipariş Beklemede</span><span class="template-status wtc-status-active">Aktif</span>
                        <mark class="order-status status-pending tips" data-tip="Ödeme bekliyor"><span>Ödeme bekliyor</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_pending_68eabc7da4382">Düzenle</a></div>
                </li>
                <li class="wtc-template-item wtc-template-inactive" data-template-id="default_processing_68eabc7da4387">
                    <div class="wtc-template-info"><span class="template-name">Sipariş Hazırlanıyor</span><span class="template-status wtc-status-inactive">Pasif</span>
                        <mark class="order-status status-processing tips" data-tip="Hazırlanıyor"><span>Hazırlanıyor</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_processing_68eabc7da4387">Düzenle</a></div>
                </li>
                <li class="wtc-template-item wtc-template-inactive" data-template-id="default_shipped_68eabc7da438a">
                    <div class="wtc-template-info"><span class="template-name">Sipariş Kargolandı</span><span class="template-status wtc-status-inactive">Pasif</span>
                        <mark class="order-status status-shipped tips" data-tip="wc-shipped"><span>wc-shipped</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_shipped_68eabc7da438a">Düzenle</a></div>
                </li>
                <li class="wtc-template-item wtc-template-inactive" data-template-id="default_completed_68eabc7da438d">
                    <div class="wtc-template-info"><span class="template-name">Sipariş Tamamlandı</span><span class="template-status wtc-status-inactive">Pasif</span>
                        <mark class="order-status status-completed tips" data-tip="Tamamlandı"><span>Tamamlandı</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_completed_68eabc7da438d">Düzenle</a></div>
                </li>
                <li class="wtc-template-item wtc-template-inactive" data-template-id="default_refund_requested_68eabc7da438f">
                    <div class="wtc-template-info"><span class="template-name">İade Talebi Oluşturuldu</span><span class="template-status wtc-status-inactive">Pasif</span>
                        <mark class="order-status status-refund-requested tips" data-tip="İade Talebi Oluşturuldu"><span>İade Talebi Oluşturuldu</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_refund_requested_68eabc7da438f">Düzenle</a></div>
                </li>
                <li class="wtc-template-item wtc-template-inactive" data-template-id="default_cancelled_68eabc7da4392">
                    <div class="wtc-template-info"><span class="template-name">Sipariş İptal Edildi</span><span class="template-status wtc-status-inactive">Pasif</span>
                        <mark class="order-status status-cancelled tips" data-tip="İptal edildi"><span>İptal edildi</span></mark>
                    </div>
                    <div class="wtc-template-actions"><a href="#" class="button button-small wtc-edit-template" data-template-id="default_cancelled_68eabc7da4392">Düzenle</a></div>
                </li>
            </ul>
            <div id="wtc-sms-edit-forms-container" style="display: none;">
                <div id="wtc-template-edit-form-default_pending_68eabc7da4382" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_pending_68eabc7da4382">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="Sipariş Beklemede" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending" selected="selected">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed">
                                    Tamamlandı </option>
                                <option value="wc-cancelled">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-pending">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">{order_id} numarali siparisiniz alinmistir. {order_total} tutarındaki odemeniz onaylandiginda isleme alinacaktir.</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_pending_68eabc7da4382">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_pending_68eabc7da4382" name="template_status" value="1" checked="checked" class="wtc-toggle-input">
                                <label for="template_status_default_pending_68eabc7da4382" class="wtc-toggle-label checked"></label>
                                <span class="toggle-status-text">Aktif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
                <div id="wtc-template-edit-form-default_processing_68eabc7da4387" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_processing_68eabc7da4387">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="Sipariş Hazırlanıyor" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing" selected="selected">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed">
                                    Tamamlandı </option>
                                <option value="wc-cancelled">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-processing">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">{order_id} numarali siparisinizin odemesi onaylandi ve hazirlama asamasina gecilmistir. Kargo bilgileri en kisa surede iletilecektir.</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_processing_68eabc7da4387">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_processing_68eabc7da4387" name="template_status" value="1" class="wtc-toggle-input">
                                <label for="template_status_default_processing_68eabc7da4387" class="wtc-toggle-label"></label>
                                <span class="toggle-status-text">Pasif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
                <div id="wtc-template-edit-form-default_shipped_68eabc7da438a" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_shipped_68eabc7da438a">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="Sipariş Kargolandı" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed">
                                    Tamamlandı </option>
                                <option value="wc-cancelled">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-shipped">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">{order_id} numarali siparisiniz kargoya verilmistir. Kargo Takip: {tracking_url}</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_shipped_68eabc7da438a">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_shipped_68eabc7da438a" name="template_status" value="1" class="wtc-toggle-input">
                                <label for="template_status_default_shipped_68eabc7da438a" class="wtc-toggle-label"></label>
                                <span class="toggle-status-text">Pasif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
                <div id="wtc-template-edit-form-default_completed_68eabc7da438d" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_completed_68eabc7da438d">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="Sipariş Tamamlandı" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed" selected="selected">
                                    Tamamlandı </option>
                                <option value="wc-cancelled">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-completed">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">Sayin {customer_name}, {order_id} numarali siparisiniz basariyla tamamlanmistir. Bizi tercih ettiginiz icin tesekkur ederiz.</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_completed_68eabc7da438d">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_completed_68eabc7da438d" name="template_status" value="1" class="wtc-toggle-input">
                                <label for="template_status_default_completed_68eabc7da438d" class="wtc-toggle-label"></label>
                                <span class="toggle-status-text">Pasif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
                <div id="wtc-template-edit-form-default_refund_requested_68eabc7da438f" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_refund_requested_68eabc7da438f">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="İade Talebi Oluşturuldu" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed">
                                    Tamamlandı </option>
                                <option value="wc-cancelled">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested" selected="selected">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-refund-requested">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">{order_id} numarali siparisinize ait iade talebiniz incelenmek uzere ekibimize iletilmistir.</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_refund_requested_68eabc7da438f">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_refund_requested_68eabc7da438f" name="template_status" value="1" class="wtc-toggle-input">
                                <label for="template_status_default_refund_requested_68eabc7da438f" class="wtc-toggle-label"></label>
                                <span class="toggle-status-text">Pasif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
                <div id="wtc-template-edit-form-default_cancelled_68eabc7da4392" class="wtc-template-edit-form" style="display: none;">
                    <form method="post" action="" class="wtc-sms-template-form">
                        <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                        <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                        <input type="hidden" name="template_id" value="default_cancelled_68eabc7da4392">
                        <div class="form-field">
                            <label for="template_name">Şablon Adı</label>
                            <input type="text" id="template_name" name="template_name" value="Sipariş İptal Edildi" required="">
                            <p class="description">Şablonu tanımlayan bir isim girin</p>
                        </div>
                        <div class="form-field">
                            <label for="template_order_status">Sipariş Durumu</label>
                            <select id="template_order_status" name="template_order_status" disabled="">
                                <option value="">Seçiniz</option>
                                <option value="wc-pending">
                                    Ödeme bekliyor </option>
                                <option value="wc-processing">
                                    Hazırlanıyor </option>
                                <option value="wc-on-hold">
                                    Beklemede </option>
                                <option value="wc-completed">
                                    Tamamlandı </option>
                                <option value="wc-cancelled" selected="selected">
                                    İptal edildi </option>
                                <option value="wc-refunded">
                                    İade edildi </option>
                                <option value="wc-failed">
                                    Başarısız </option>
                                <option value="wc-checkout-draft">
                                    Taslak </option>
                                <option value="wc-refund-requested">
                                    İade Talebi Oluşturuldu </option>
                                <option value="wc-refund-rejected">
                                    İade Reddedildi </option>
                                <option value="wc-refund-cancelled">
                                    İade Talebi İptal Edildi </option>
                            </select>
                            <input type="hidden" name="template_order_status" value="wc-cancelled">
                            <p class="description">Varsayılan şablonların sipariş durumu değiştirilemez</p>
                        </div>
                        <div class="form-field">
                            <label for="template_content">Şablon İçeriği</label>
                            <textarea id="template_content" name="template_content" rows="5" required="">{order_id} numarali siparisiniz iptal edilmistir. Odeme yaptiysaniz ucret iadeniz en kisa surede baslatilacaktir.</textarea>
                            <div class="wtc-template-variables">
                                <div class="variable-category">
                                    <div class="variable-buttons">
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                            Sipariş ID </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                            Sipariş Tutarı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                            Sipariş Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                            Müşteri Adı </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                            Kargo Firması </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                            Gönderim Tarihi </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                            Kargo Takip No </button>
                                        <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                            Kargo Takip URL </button>
                                    </div>
                                </div>
                            </div>
                            <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                        </div>
                        <div class="form-field">
                            <label for="template_status_default_cancelled_68eabc7da4392">Durum</label>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="template_status_default_cancelled_68eabc7da4392" name="template_status" value="1" class="wtc-toggle-input">
                                <label for="template_status_default_cancelled_68eabc7da4392" class="wtc-toggle-label"></label>
                                <span class="toggle-status-text">Pasif</span>
                            </div>
                        </div>
                        <div class="form-field">
                            <button type="submit" class="button button-primary wtc-save-template">
                                Güncelle </button>
                            <button type="button" class="button wtc-cancel-edit">
                                İptal </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="wtc-sms-template-add">
            <h3>Yeni SMS Şablonu Ekle</h3>
            <form method="post" action="" class="wtc-sms-template-form">
                <input type="hidden" id="wtc_sms_template_nonce" name="wtc_sms_template_nonce" value="ac5ee82df6">
                <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=templates">
                <input type="hidden" name="template_id" value="">
                <div class="form-field">
                    <label for="template_name">Şablon Adı</label>
                    <input type="text" id="template_name" name="template_name" value="" required="">
                    <p class="description">Şablonu tanımlayan bir isim girin</p>
                </div>
                <div class="form-field">
                    <label for="template_order_status">Sipariş Durumu</label>
                    <select id="template_order_status" name="template_order_status" required="">
                        <option value="">Seçiniz</option>
                        <option value="wc-pending">
                            Ödeme bekliyor </option>
                        <option value="wc-processing">
                            Hazırlanıyor </option>
                        <option value="wc-on-hold">
                            Beklemede </option>
                        <option value="wc-completed">
                            Tamamlandı </option>
                        <option value="wc-cancelled">
                            İptal edildi </option>
                        <option value="wc-refunded">
                            İade edildi </option>
                        <option value="wc-failed">
                            Başarısız </option>
                        <option value="wc-checkout-draft">
                            Taslak </option>
                        <option value="wc-refund-requested">
                            İade Talebi Oluşturuldu </option>
                        <option value="wc-refund-rejected">
                            İade Reddedildi </option>
                        <option value="wc-refund-cancelled">
                            İade Talebi İptal Edildi </option>
                    </select>
                    <p class="description">Bu şablonun hangi sipariş durumunda kullanılacağını seçin</p>
                </div>
                <div class="form-field">
                    <label for="template_content">Şablon İçeriği</label>
                    <textarea id="template_content" name="template_content" rows="5" required=""></textarea>
                    <div class="wtc-template-variables">
                        <div class="variable-category">
                            <div class="variable-buttons">
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_id}" title="{order_id}">
                                    Sipariş ID </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_total}" title="{order_total}">
                                    Sipariş Tutarı </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{order_date}" title="{order_date}">
                                    Sipariş Tarihi </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{customer_name}" title="{customer_name}">
                                    Müşteri Adı </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{company_name}" title="{company_name}">
                                    Kargo Firması </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{shipped_date}" title="{shipped_date}">
                                    Gönderim Tarihi </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_no}" title="{tracking_no}">
                                    Kargo Takip No </button>
                                <button type="button" class="button button-secondary wtc-insert-variable" data-variable="{tracking_url}" title="{tracking_url}">
                                    Kargo Takip URL </button>
                            </div>
                        </div>
                    </div>
                    <p class="description">SMS şablonunun içeriğini girin. Yukarıdaki değişkenleri kullanabilirsiniz.</p>
                </div>
                <div class="form-field">
                    <label for="template_status_new">Durum</label>
                    <div class="wtc-toggle-wrapper">
                        <input type="checkbox" id="template_status_new" name="template_status" value="1" checked="checked" class="wtc-toggle-input">
                        <label for="template_status_new" class="wtc-toggle-label checked"></label>
                        <span class="toggle-status-text">Aktif</span>
                    </div>
                </div>
                <div class="form-field">
                    <button type="submit" class="button button-primary wtc-save-template">
                        Ekle </button>
                </div>
            </form>
        </div>
    </div>
    <?php }
    private function render_sms_logs_tab() {  ?>
    <div class="wtc-sms-logs-cleanup">
        <h3>SMS Kayıtları Temizleme Ayarları</h3>
        <form method="post" action="">
            <input type="hidden" name="action" value="wtc_sms_cleanup_settings">
            <input type="hidden" id="wtc_sms_cleanup_nonce" name="wtc_sms_cleanup_nonce" value="e3f0c0b1c3">
            <input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=wtc-sms&amp;tab=logs">
            <table class="form-table">
                <tbody>
                    <tr>
                        <th>Temizleme Periyodu</th>
                        <td>
                            <select name="sms_cleanup_period">
                                <option value="manual">Kapalı</option>
                                <option value="daily" selected="selected">Günlük</option>
                                <option value="weekly">Haftalık</option>
                                <option value="monthly">Aylık</option>
                                <option value="quarterly">3 Aylık</option>
                                <option value="yearly">Yıllık</option>
                            </select>
                            <p class="description">SMS kayıtlarının otomatik olarak temizleneceği süreyi belirleyin.</p>
                        </td>
                    </tr>
                </tbody>
            </table>
            <p class="submit">
                <input type="submit" class="button button-primary" value="Ayarları Kaydet">
                <button type="button" id="wtc-delete-all-logs" class="button button-secondary">Tüm Kayıtları Sil</button>
            </p>
        </form>
    </div>
    <div class="wtc-sms-logs-filter">
        <h3>SMS Kayıtlarını Filtrele</h3>
        <form method="get" action="">
            <input type="hidden" name="page" value="wtc-sms">
            <input type="hidden" name="tab" value="logs">
            <table class="form-table">
                <tbody>
                    <tr>
                        <th>Başlangıç Tarihi</th>
                        <td>
                            <input type="date" name="sms_start_date" value="">
                        </td>
                        <th>Bitiş Tarihi</th>
                        <td>
                            <input type="date" name="sms_end_date" value="">
                        </td>
                    </tr>
                    <tr>
                        <th>Sipariş ID</th>
                        <td>
                            <input type="text" name="sms_order_id" value="">
                        </td>
                        <th>SMS Durumu</th>
                        <td>
                            <select name="sms_status">
                                <option value="">Tüm SMS Durumları</option>
                                <option value="success">Başarılı</option>
                                <option value="error">Başarısız</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
            <p class="submit">
                <input type="submit" class="button button-primary" value="Filtrele">
                <a href="admin.php?page=wtc-sms&amp;tab=logs" class="button button-secondary">Filtreleri Temizle</a>
            </p>
        </form>
    </div>
    <div class="wtc-sms-logs">
        <h3>SMS Kayıtları</h3>
        <p>Belirtilen kriterlere uygun SMS kaydı bulunamadı.</p>
    </div>
    <?php } private function render_sms_settings() { ?>
        <form method="post" action="" id="wtc-sms-settings-form">
        <input type="hidden" name="wtc_action" value="save_sms_settings">
        <input type="hidden" name="wtc_sms_nonce" value="7414daab09">
        <!-- Ana Ayarlar -->
        <div class="wtc-settings-section">
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">SMS Bildirimleri</th>
                        <td>
                            <div class="wtc-toggle-wrapper">
                                <input type="checkbox" id="sms_enabled" name="sms_enabled" value="1" class="wtc-toggle-input">
                                <label for="sms_enabled" class="wtc-toggle-label"></label>
                                <span class="toggle-label">SMS bildirimlerini etkinleştir</span>
                            </div>
                            <p class="description">Kargo bilgileri güncellendiğinde müşteriye otomatik SMS gönderilir.</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="wtc-settings-section">
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">SMS Sağlayıcısı</th>
                        <td>
                            <select name="sms_provider" id="sms-provider">
                                <option value="">Seçiniz</option>
                                <option value="NETGSM">NETGSM</option>
                                <option value="KOBIKOM">KOBIKOM</option>
                                <option value="VERIMOR">VERIMOR</option>
                                <option value="MUTLUCELL">MUTLUCELL</option>
                                <option value="ILETIMERKEZI" selected="selected">ILETIMERKEZI</option>
                            </select>
                            <p class="description">SMS gönderimi için kullanılacak servis sağlayıcısını seçin.</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- NetGSM Ayarları -->
        <div id="netgsm-settings" class="provider-settings wtc-settings-section" style="display: none">
            <h3>NetGSM Ayarları</h3>
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">Kullanıcı Adı</th>
                        <td>
                            <input type="text" name="netgsm_user" value="123456789" class="regular-text">
                            <p class="description">NetGSM kullanıcı adınız</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Şifre</th>
                        <td>
                            <input type="password" name="netgsm_pass" value="123456789" class="regular-text">
                            <p class="description">NetGSM şifreniz</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Başlık (Header)</th>
                        <td>
                            <input type="text" name="netgsm_header" value="123456789" class="regular-text">
                            <p class="description">NetGSM SMS başlığı (onaylı başlık olmalıdır)</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- Kobikom Ayarları -->
        <div id="kobikom-settings" class="provider-settings wtc-settings-section" style="display: none">
            <h3>Kobikom Ayarları</h3>
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">API Token</th>
                        <td>
                            <input type="text" name="kobikom_user" value="123456789" class="regular-text">
                            <p class="description">Kobikom SMS panelindeki "Ayarlar &gt; SMS API" menüsünden alacağınız API anahtarı</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Şifre</th>
                        <td>
                            <input type="password" name="kobikom_pass" value="" class="regular-text" disabled="">
                            <p class="description">Kobikom API için şifre gerekli değildir. Lütfen sadece API Token kullanınız.</p>
                            <input type="hidden" name="kobikom_pass" value="">
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Başlık (Header)</th>
                        <td>
                            <input type="text" name="kobikom_header" value="123456789" class="regular-text">
                            <p class="description">Kobikom SMS başlığı (onaylı başlık olmalıdır, "from" parametresi)</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- Verimor Ayarları -->
        <div id="verimor-settings" class="provider-settings wtc-settings-section" style="display: none">
            <h3>Verimor Ayarları</h3>
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">Kullanıcı Adı</th>
                        <td>
                            <input type="text" name="verimor_user" value="123456789" class="regular-text">
                            <p class="description">Verimor kullanıcı adınız (genellikle 8 haneli müşteri numarası)</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Şifre</th>
                        <td>
                            <input type="password" name="verimor_pass" value="123456789" class="regular-text">
                            <p class="description">Verimor API şifreniz</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Başlık (Header)</th>
                        <td>
                            <input type="text" name="verimor_header" value="123456789" class="regular-text">
                            <p class="description">Verimor SMS başlığı (onaylı başlık olmalıdır, Türkçe karakter kullanılamaz ve 11 karakterle sınırlıdır)</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- Mutlucell Ayarları -->
        <div id="mutlucell-settings" class="provider-settings wtc-settings-section" style="display: none">
            <h3>Mutlucell Ayarları</h3>
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">Kullanıcı Adı</th>
                        <td>
                            <input type="text" name="mutlucell_user" value="123456789" class="regular-text">
                            <p class="description">Mutlucell kullanıcı adınız</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Şifre</th>
                        <td>
                            <input type="password" name="mutlucell_pass" value="123456789" class="regular-text">
                            <p class="description">Mutlucell şifreniz</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Başlık (Header)</th>
                        <td>
                            <input type="text" name="mutlucell_header" value="123456789" class="regular-text">
                            <p class="description">Mutlucell SMS başlığı (org parametresi, onaylı başlık olmalıdır)</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- İletiMerkezi Ayarları -->
        <div id="iletimerkezi-settings" class="provider-settings wtc-settings-section" style="display: block">
            <h3>İletiMerkezi Ayarları</h3>
            <table class="form-table wtc-form-table">
                <tbody>
                    <tr>
                        <th scope="row">API Anahtarı</th>
                        <td>
                            <input type="text" name="iletimerkezi_key" value="123456789" class="regular-text">
                            <p class="description">İletiMerkezi API Anahtarı (iletimerkezi.com panelinizin ayarlar bölümünden alabilirsiniz)</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">API Hash</th>
                        <td>
                            <input type="password" name="iletimerkezi_hash" value="123456789" class="regular-text">
                            <p class="description">İletiMerkezi API Hash değeri (iletimerkezi.com panelinizin ayarlar bölümünden alabilirsiniz)</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Başlık (Sender)</th>
                        <td>
                            <input type="text" name="iletimerkezi_sender" value="123456789" class="regular-text">
                            <p class="description">İletiMerkezi SMS başlığı (onaylı başlık olmalıdır, maksimum 11 karakter)</p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <p class="submit">
            <input type="submit" name="submit" id="submit" class="button button-primary" value="Ayarları Kaydet">
        </p>
    </form>
    <?php
    }
} 