<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

$has_groups = ! empty( KNSDD_Data::get_groups() );
?>
<div id="knsdd-status-management" class="knsdd-card">
    <div class="knsdd-card-header">
        <h2><?php esc_html_e( 'Mevcut Gruplar', 'kns-dynamic-discounts-for-woocommerce' ); ?></h2>
        <div class="knsdd-import-export-toolbar">
            <?php $is_locked = true; ?>
            
            <!-- Export Button (opens modal) -->
            <div class="knsdd-export-wrapper">
                <button type="button" 
                        class="button button-secondary<?php echo $is_locked ? ' knsdd-pro-locked-action' : ''; ?>" 
                        id="knsdd-export-button" 
                        aria-haspopup="true" 
                        aria-expanded="false"
                        <?php if ( $is_locked ) : ?>
                            data-upgrade-url="<?php echo esc_url( KNSDD_License::get_upgrade_url( 'groups_export' ) ); ?>"
                            title="<?php echo esc_attr__( 'Export/Import Pro özelliğidir. Upgrade edin.', 'kns-dynamic-discounts-for-woocommerce' ); ?>"
                        <?php endif; ?>>
                    <?php esc_html_e( 'Dışa Aktar', 'kns-dynamic-discounts-for-woocommerce' ); ?>
                    <?php if ( $is_locked ) echo wp_kses_post( KNSDD_License::pro_badge() ); ?>
                </button>
            </div>
            
            <!-- Import Button -->
            <button type="button" 
                    class="button button-secondary<?php echo $is_locked ? ' knsdd-pro-locked-action' : ''; ?>" 
                    id="knsdd-import-groups"
                    <?php if ( $is_locked ) : ?>
                        data-upgrade-url="<?php echo esc_url( KNSDD_License::get_upgrade_url( 'groups_import' ) ); ?>"
                        title="<?php echo esc_attr__( 'Export/Import Pro özelliğidir. Upgrade edin.', 'kns-dynamic-discounts-for-woocommerce' ); ?>"
                    <?php endif; ?>>
                <?php esc_html_e( 'İçe Aktar', 'kns-dynamic-discounts-for-woocommerce' ); ?>
                <?php if ( $is_locked ) echo wp_kses_post( KNSDD_License::pro_badge() ); ?>
            </button>
        </div>
    </div>

    <div class="knsdd-filters">
        <input type="search" id="knsdd-group-search" placeholder="<?php esc_attr_e( 'Grup adında ara...', 'kns-dynamic-discounts-for-woocommerce' ); ?>">
        
        <label for="knsdd-status-filter" class="knsdd-filter-label" title="<?php echo esc_attr__( 'Durum', 'kns-dynamic-discounts-for-woocommerce' ); ?>:"><?php esc_html_e( 'Durum', 'kns-dynamic-discounts-for-woocommerce' ); ?>:</label>
        <div class="knsdd-status-filter-wrapper">
            <button type="button" id="knsdd-status-filter-toggle" class="knsdd-status-filter-button" aria-haspopup="true" aria-expanded="false">
                <span class="knsdd-status-filter-text"><?php esc_html_e( 'Tüm Durumlar', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
            </button>
            <div id="knsdd-status-filter-dropdown" class="knsdd-status-filter-dropdown" role="menu" style="display: none;">
                <div class="knsdd-status-filter-option" data-value="all" role="menuitem">
                    <span><?php esc_html_e( 'Tüm Durumlar', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-checkbox-item" data-value="open" role="menuitemcheckbox" aria-checked="false">
                    <span><?php esc_html_e( 'Aktif', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                    <input type="checkbox" value="open" tabindex="-1">
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-checkbox-item" data-value="closed-pending" role="menuitemcheckbox" aria-checked="false">
                    <span><?php esc_html_e( 'Beklemede', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                    <input type="checkbox" value="closed-pending" tabindex="-1">
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-checkbox-item" data-value="closed-expired" role="menuitemcheckbox" aria-checked="false">
                    <span><?php esc_html_e( 'Tamamlandı', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                    <input type="checkbox" value="closed-expired" tabindex="-1">
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-checkbox-item" data-value="paused" role="menuitemcheckbox" aria-checked="false">
                    <span><?php esc_html_e( 'Manuel Pasif', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                    <input type="checkbox" value="paused" tabindex="-1">
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-checkbox-item" data-value="closed-incomplete" role="menuitemcheckbox" aria-checked="false">
                    <span><?php esc_html_e( 'Tarih Belirtilmedi', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                    <input type="checkbox" value="closed-incomplete" tabindex="-1">
                </div>
                <div class="knsdd-status-filter-option knsdd-status-filter-clear" data-value="clear" role="menuitem">
                    <span><?php esc_html_e( 'Seçimleri Temizle', 'kns-dynamic-discounts-for-woocommerce' ); ?></span>
                </div>
            </div>
        </div>
        
        <label for="knsdd-group-sort" class="knsdd-filter-label" title="<?php echo esc_attr__( 'Sırala:', 'kns-dynamic-discounts-for-woocommerce' ); ?>"><?php esc_html_e( 'Sırala:', 'kns-dynamic-discounts-for-woocommerce' ); ?></label>
        <select id="knsdd-group-sort">
            <option value="all"><?php esc_html_e( 'Tümü', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="creation-desc"><?php esc_html_e( 'Oluşturulma Tarihi (En Yeni)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="creation-asc"><?php esc_html_e( 'Oluşturulma Tarihi (En Eski)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="start-date-asc"><?php esc_html_e( 'Başlangıç Tarihi (En Önce Başlayacak Olan)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="start-date-desc"><?php esc_html_e( 'Başlangıç Tarihi (En Son Başlayacak Olan)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="end-date-asc"><?php esc_html_e( 'Bitiş Tarihi (En Önce Bitecek Olan)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="end-date-desc"><?php esc_html_e( 'Bitiş Tarihi (En Son Bitecek Olan)', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
        </select>

        <label for="knsdd-advanced-filter" class="knsdd-filter-label" title="<?php echo esc_attr__( 'Gelişmiş:', 'kns-dynamic-discounts-for-woocommerce' ); ?>"><?php esc_html_e( 'Gelişmiş:', 'kns-dynamic-discounts-for-woocommerce' ); ?></label>
        <select id="knsdd-advanced-filter">
            <option value="all"><?php esc_html_e( 'Tümü', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="has_rules"><?php esc_html_e( 'Sadece Kuralı Olanlar', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="no_rules"><?php esc_html_e( 'Kuralı Olmayanlar', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="has_special_campaign"><?php esc_html_e( 'Özel Kampanya İçerenler', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="has_standard_discount"><?php esc_html_e( 'Miktar İndirimi İçerenler', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="has_members_only"><?php esc_html_e( 'Üyelere Özel İndirim İçerenler', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            <option value="has_first_order_only"><?php esc_html_e( 'İlk Sipariş İndirimi İçerenler', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
        </select>
    </div>

    <table class="wp-list-table widefat fixed striped" id="knsdd-toggle-table">
        <thead>
            <tr>
                <th><?php esc_html_e( 'Grup Adı', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
                <th><?php esc_html_e( 'Başlangıç', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
                <th><?php esc_html_e( 'Bitiş', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
                <th><?php esc_html_e( 'Durum', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
                <th><?php esc_html_e( 'Durum Bilgisi', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
                <th class="knsdd-actions-column"><?php esc_html_e( 'İşlemler', 'kns-dynamic-discounts-for-woocommerce' ); ?></th>
            </tr>
        </thead>
        <tbody id="knsdd-toggle-tbody">
        <?php if ( ! $has_groups ) : ?>
            <tr><td colspan="6"><?php esc_html_e( 'Başlamak için lütfen bir grup oluşturun.', 'kns-dynamic-discounts-for-woocommerce' ); ?></td></tr>
        <?php endif; ?>
        </tbody>
    </table>

    <!-- Toplu İşlemler + Sayfalama -->
    <div class="knsdd-table-footer">
        <!-- Toplu İşlemler Toolbar -->
        <div class="knsdd-bulk-actions-toolbar" style="display:none;">
            <select id="knsdd-bulk-action-select">
                <option value=""><?php esc_html_e( 'Toplu İşlemler', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
                <option value="select-all" id="bulk-action-select-all"><?php esc_html_e( 'Tümünü Seç', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
                <option value="deselect-all" id="bulk-action-deselect-all"><?php esc_html_e( 'Seçimi Temizle', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
                <option value="" disabled>──────────</option>
                <option value="delete" id="bulk-action-delete"><?php esc_html_e( 'Seçilenleri Sil', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
                <option value="pause" id="bulk-action-pause"><?php esc_html_e( 'Seçilenleri Manuel Pasif Yap', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
                <option value="unpause" id="bulk-action-unpause"><?php esc_html_e( 'Seçilenleri Manuel Aktif Yap', 'kns-dynamic-discounts-for-woocommerce' ); ?></option>
            </select>
            <button type="button" id="knsdd-bulk-apply" class="button" disabled>
                <?php esc_html_e( 'Uygula', 'kns-dynamic-discounts-for-woocommerce' ); ?>
            </button>
            <span id="knsdd-selected-count-wrapper" style="display:none;">
                (<span id="knsdd-selected-count">0</span> <?php esc_html_e( 'seçili', 'kns-dynamic-discounts-for-woocommerce' ); ?>)
            </span>
        </div>

        <!-- Sayfalama Kontrolleri -->
        <div id="knsdd-pagination" class="knsdd-pagination" style="display:none;">
            <div class="knsdd-pagination-info">
                <span id="knsdd-pagination-info"></span>
            </div>
            <div class="knsdd-pagination-controls">
                <button type="button" id="knsdd-pagination-first" class="button" title="<?php esc_attr_e( 'İlk Sayfa', 'kns-dynamic-discounts-for-woocommerce' ); ?>">«</button>
                <button type="button" id="knsdd-pagination-prev" class="button" title="<?php esc_attr_e( 'Önceki', 'kns-dynamic-discounts-for-woocommerce' ); ?>">‹</button>
                <button type="button" id="knsdd-pagination-next" class="button" title="<?php esc_attr_e( 'Sonraki', 'kns-dynamic-discounts-for-woocommerce' ); ?>">›</button>
                <button type="button" id="knsdd-pagination-last" class="button" title="<?php esc_attr_e( 'Son Sayfa', 'kns-dynamic-discounts-for-woocommerce' ); ?>">»</button>
            </div>
        </div>
    </div>
</div>
