<?php
/**
 * ============================================================================
 * EONSR CSV BULK GENERATION - ADMIN UI PAGE
 * 
 * @description  Giao diện tạo bài viết hàng loạt từ file Excel (Bulk Processor).
 * @package      EONSR_AEO_Agent
 * @subpackage   Includes
 * @version      2.0 (Refactored)
 * ============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Render the Bulk Generate Page.
 */
function eonsr_aeo_agent_bulk_generate_page()
{
    // =========================================================================
    // [SECTION 1] LICENSE VALIDATION
    // =========================================================================
    // Updated function name with prefix
    // $validation_result = eonsr_aeo_agent_validate_license_key();

    $validation_result = ['success' => true, 'message' => ''];
    
    if ( ! $validation_result['success'] ) {
        ?>
        <div class="wrap">
            <h1>Tạo bài hàng loạt</h1>
            <div class="notice notice-error">
                <p>Lỗi Bản Quyền: <?php echo esc_html($validation_result['message']); ?></p>
            </div>
        </div>
        <?php
        return;
    }

    // =========================================================================
    // [SECTION 2] CONFIGURATION & FEATURE FLAGS
    // =========================================================================
    // Updated option name
    $features = get_option('eonsr_aeo_agent_license_features', []);
    
    // Limits from Plan
    $f_min_words   = 800;
    $f_max_words   = 3500;
    // $f_ai_model    = $features['aiModel'] ?? 'EONSR Pro';
    $f_ai_model    = 'EONSR Pro';
    // $f_allow_yt    = $features['allowYoutube'] ?? false;
    $f_langs_limit = $features['allowedLanguageCount'] ?? 24;
    
    // Custom Logo Configuration
    $allow_logo = isset($features['allowCustomLogo']) ? $features['allowCustomLogo'] : false;
    // Updated option name
    $use_logo   = get_option('eonsr_aeo_agent_use_custom_logo', false);
    
    if ( ! $allow_logo ) {
        $use_logo = false; // Force disable if not allowed
    }
    // Updated option name
    $current_logo_url = get_option('eonsr_aeo_agent_custom_logo_url');

    // =========================================================================
    // [SECTION 3] DATA RETRIEVAL (SAVED SETTINGS & CONSTANTS)
    // =========================================================================
    
    // Saved User Preferences (Updated option names)
    $saved_langs     = get_option('eonsr_aeo_agent_selected_languages', ['Vietnamese', 'English']);
    $saved_countries = get_option('eonsr_aeo_agent_selected_countries', ['VN', 'US']);
    $saved_styles    = get_option('eonsr_aeo_agent_selected_styles', ['Mac dinh']);

    // CSV Sample URL
    $plugin_url     = plugin_dir_url( dirname( __FILE__ ) ); 
    $csv_sample_url = $plugin_url . 'assets/csv/bulk_template.xlsx';

    // Data Source: Countries
    $all_countries = [
        'VN' => ['name' => 'Vietnam', 'flag' => '🇻🇳'],
        'US' => ['name' => 'United States', 'flag' => '🇺🇸'],
        'GB' => ['name' => 'United Kingdom', 'flag' => '🇬🇧'],
        'FR' => ['name' => 'France', 'flag' => '🇫🇷'],
        'DE' => ['name' => 'Germany', 'flag' => '🇩🇪'],
        'JP' => ['name' => 'Japan', 'flag' => '🇯🇵'],
        'KR' => ['name' => 'South Korea', 'flag' => '🇰🇷'],
        'CN' => ['name' => 'China', 'flag' => '🇨🇳'],
        'RU' => ['name' => 'Russia', 'flag' => '🇷🇺'],
        'ES' => ['name' => 'Spain', 'flag' => '🇪🇸'],
        'IT' => ['name' => 'Italy', 'flag' => '🇮🇹'],
        'CA' => ['name' => 'Canada', 'flag' => '🇨🇦'],
        'AU' => ['name' => 'Australia', 'flag' => '🇦🇺'],
        'IN' => ['name' => 'India', 'flag' => '🇮🇳'],
        'BR' => ['name' => 'Brazil', 'flag' => '🇧🇷'],
        'TH' => ['name' => 'Thailand', 'flag' => '🇹🇭'],
        'ID' => ['name' => 'Indonesia', 'flag' => '🇮🇩'],
        'SG' => ['name' => 'Singapore', 'flag' => '🇸🇬'],
        'MY' => ['name' => 'Malaysia', 'flag' => '🇲🇾'],
        'PH' => ['name' => 'Philippines', 'flag' => '🇵🇭'],
        'TR' => ['name' => 'Turkey', 'flag' => '🇹🇷'],
        'SA' => ['name' => 'Saudi Arabia', 'flag' => '🇸🇦'],
        'AE' => ['name' => 'UAE', 'flag' => '🇦🇪'],
        'ZA' => ['name' => 'South Africa', 'flag' => '🇿🇦'],
        'NG' => ['name' => 'Nigeria', 'flag' => '🇳🇬'],
        'EG' => ['name' => 'Egypt', 'flag' => '🇪🇬'],
        'AR' => ['name' => 'Argentina', 'flag' => '🇦🇷'],
        'MX' => ['name' => 'Mexico', 'flag' => '🇲🇽'],
        'NL' => ['name' => 'Netherlands', 'flag' => '🇳🇱'],
        'SE' => ['name' => 'Sweden', 'flag' => '🇸🇪'],
        'NO' => ['name' => 'Norway', 'flag' => '🇳🇴'],
        'DK' => ['name' => 'Denmark', 'flag' => '🇩🇰'],
        'FI' => ['name' => 'Finland', 'flag' => '🇫🇮'],
        'PL' => ['name' => 'Poland', 'flag' => '🇵🇱'],
        'UA' => ['name' => 'Ukraine', 'flag' => '🇺🇦'],
        'PT' => ['name' => 'Portugal', 'flag' => '🇵🇹'],
        'IL' => ['name' => 'Israel', 'flag' => '🇮🇱']
    ];

    // --- Data Source: Languages (Full List) ---
    $all_languages = [
        'Vietnamese' => ['name' => 'Tiếng Việt', 'flag' => '🇻🇳'],
        'English'    => ['name' => 'English', 'flag' => '🇺🇸'],
        'French'     => ['name' => 'Français', 'flag' => '🇫🇷'],
        'German'     => ['name' => 'Deutsch', 'flag' => '🇩🇪'],
        'Japanese'   => ['name' => '日本語', 'flag' => '🇯🇵'],
        'Korean'     => ['name' => '한국어', 'flag' => '🇰🇷'],
        'Chinese'    => ['name' => '中文', 'flag' => '🇨🇳'],
        'Russian'    => ['name' => 'Русский', 'flag' => '🇷🇺'],
        'Spanish'    => ['name' => 'Español', 'flag' => '🇪🇸'],
        'Italian'    => ['name' => 'Italiano', 'flag' => '🇮🇹'],
        'Thai'       => ['name' => 'ไทย', 'flag' => '🇹🇭'],
        'Indonesian' => ['name' => 'Bahasa Indonesia', 'flag' => '🇮🇩'],
        'Portuguese' => ['name' => 'Português', 'flag' => '🇵🇹'],
        'Hindi'      => ['name' => 'हिन्दी', 'flag' => '🇮🇳'],
        'Arabic'     => ['name' => 'العربية', 'flag' => '🇸🇦'],
        'Turkish'    => ['name' => 'Türkçe', 'flag' => '🇹🇷'],
        'Dutch'      => ['name' => 'Nederlands', 'flag' => '🇳🇱'],
        'Swedish'    => ['name' => 'Svenska', 'flag' => '🇸🇪'],
        'Norwegian'  => ['name' => 'Norsk', 'flag' => '🇳🇴'],
        'Danish'     => ['name' => 'Dansk', 'flag' => '🇩🇰'],
        'Finnish'    => ['name' => 'Suomi', 'flag' => '🇫🇮'],
        'Polish'     => ['name' => 'Polski', 'flag' => '🇵🇱'],
        'Ukrainian'  => ['name' => 'Українська', 'flag' => '🇺🇦'],
        'Hebrew'     => ['name' => 'עברית', 'flag' => '🇮🇱']
    ];

    // Data Source: Styles
    $all_styles = [
        'Mac dinh'       => ['name' => 'EONSR Style (Chuẩn SEO)'],
        'Sleek Blog'     => ['name' => 'Sleek Blog (Hiện đại)'],
        'Urban Polished' => ['name' => 'Urban Polished (Chuyên nghiệp)'],
        'Universe'       => ['name' => 'Universe (Sáng tạo)'],
    ];
    ?>

    <!-- Updated Wrapper Class -->
    <div class="wrap eonsr-aeo-agent-wrapper">
        
        <!-- ===================================================================
             HEADER SECTION
        =================================================================== -->
        <div class="eonsr-aeo-page-header">
            <div class="header-content">
                <h1 class="wp-heading-inline">📦 Tạo bài viết hàng loạt (Bulk Generate)</h1>
                <p class="header-subtitle">Tự động hóa quy trình nội dung với file Excel và AI.</p>
            </div>
            <div class="header-actions">
                <a href="<?php echo esc_url($csv_sample_url); ?>" class="button button-primary download-template-btn" download>
                    <span class="dashicons dashicons-download"></span> Tải file mẫu XLSX
                </a>
            </div>
        </div>
        
        <hr class="wp-header-end" style="display:none;">

        <!-- ===================================================================
             GUIDE SECTION (3 STEPS)
        =================================================================== -->
        <div class="eonsr-aeo-guide-section">
            <div class="guide-card step-1">
                <div class="guide-icon"><span class="dashicons dashicons-media-spreadsheet"></span></div>
                <div class="guide-info">
                    <h3>1. Chuẩn bị File</h3>
                    <p>Tải file mẫu ở trên. File cần đúng định dạng <strong>.xlsx</strong>.</p>
                    <div class="limit-badge">
                        <span class="dashicons dashicons-warning"></span> Giới hạn: Tối đa 50 dòng / file
                    </div>
                </div>
            </div>
            <div class="guide-card step-2">
                <div class="guide-icon"><span class="dashicons dashicons-editor-table"></span></div>
                <div class="guide-info">
                    <h3>2. Cấu trúc Cột (Bắt buộc)</h3>
                    <ul class="guide-list">
                        <li><code>primary_term</code>: Từ khóa chính.</li>
                        <li><code>audience</code>: Khách hàng mục tiêu.</li>
                        <li><code>time_to_publish</code>: Thời gian đăng.</li>
                    </ul>
                </div>
            </div>
            <div class="guide-card step-3">
                <div class="guide-icon"><span class="dashicons dashicons-clock"></span></div>
                <div class="guide-info">
                    <h3>3. Định dạng Thời gian</h3>
                    <p>Format: <code class="highlight">DD/MM/YY HH:MM</code></p>
                    <p class="warning-text"><span class="dashicons dashicons-warning"></span> Hẹn giờ cách hiện tại > 15 phút.</p>
                </div>
            </div>
        </div>
        
        <!-- CODE PREVIEW BLOCK -->
        <div class="eonsr-aeo-code-preview">
            <div class="preview-label">Ví dụ dữ liệu chuẩn:</div>
            <div class="preview-content">
                <span class="col-name">primary_term</span> <span class="sep">|</span> 
                <span class="col-name">audience</span> <span class="sep">|</span> 
                <span class="col-name">time_to_publish</span>
                <br>
                <span class="col-val">Review iPhone 16</span> <span class="sep">|</span> 
                <span class="col-val">Người yêu công nghệ</span> <span class="sep">|</span> 
                <span class="col-val">24/01/25 08:30</span>
            </div>
        </div>

        <!-- ===================================================================
             MAIN DASHBOARD GRID
        =================================================================== -->
        <div class="eonsr-aeo-dashboard-grid">
            
            <!-- [COL LEFT] CONFIG & UPLOAD FORM -->
            <div class="eonsr-aeo-col-left">
                <div class="eonsr-aeo-card config-card">
                    <div class="eonsr-aeo-card-header">
                        <h2>⚙️ Cấu hình & Upload</h2>
                    </div>
                    <div class="eonsr-aeo-card-body">
                        <!-- Updated Form ID -->
                        <form id="aeo-agent-bulk-form" enctype="multipart/form-data">
                            
                            <!-- 1. MODEL AI -->
                            <div class="form-group">
                                <label class="eonsr-aeo-agent-label">Model AI</label>
                                <select name="model_name" class="eonsr-aeo-agent-select full-width">
                                    <option value="gemini-3-flash-preview" selected>EONSR Lite</option>
                                    
                                    <?php if ( stripos($f_ai_model, 'Lite') === false ): ?>
                                        <option value="gemini-3-flash-preview">EONSR Pro</option>
                                    <?php endif; ?>
                                </select>
                                <?php if ( stripos($f_ai_model, 'Lite') !== false ): ?>
                                    <!-- <small style="color:#d63638; font-size:11px;">Nâng cấp gói để mở khóa EONSR Pro</small> -->
                                <?php endif; ?>
                            </div>

                            <!-- 2. LANGUAGE & COUNTRY -->
                            <div class="form-row">
                                <div class="form-group half">
                                    <label class="eonsr-aeo-agent-label">Ngôn ngữ gốc</label>
                                    <select name="language" id="bulk_source_language" class="eonsr-aeo-agent-select">
                                        <?php 
                                        foreach ($saved_langs as $l_code) {
                                            $l_data  = $all_languages[$l_code] ?? null;
                                            $l_label = is_array($l_data) ? $l_data['flag'] . ' ' . $l_data['name'] : $l_code;
                                            echo "<option value='".esc_attr($l_code)."'>".esc_html($l_label)."</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                                <div class="form-group half">
                                    <label class="eonsr-aeo-agent-label">Quốc gia</label>
                                    <select name="country" class="eonsr-aeo-agent-select">
                                        <?php 
                                        foreach ($saved_countries as $c_code) {
                                            $c_data  = $all_countries[$c_code] ?? null;
                                            $c_label = is_array($c_data) ? $c_data['flag'] . ' ' . $c_data['name'] : $c_code;
                                            echo "<option value='".esc_attr($c_code)."'>".esc_html($c_label)."</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>

                            <!-- 3. WRITING STYLE -->
                            <div class="form-group">
                                <label class="eonsr-aeo-agent-label">Phong cách viết</label>
                                <select name="output_style" class="eonsr-aeo-agent-select full-width">
                                    <?php 
                                    foreach ($saved_styles as $s_code) {
                                        $s_name = isset($all_styles[$s_code]) ? $all_styles[$s_code]['name'] : $s_code;
                                        echo "<option value='".esc_attr($s_code)."'>".esc_html($s_name)."</option>";
                                    }
                                    ?>
                                </select>
                            </div>

                            <!-- 4. WORD COUNT -->
                            <div class="form-group">
                                <label class="eonsr-aeo-agent-label">Số từ tối thiểu</label>
                                <select name="min_words" class="eonsr-aeo-agent-select full-width">
                                    <?php
                                    $word_options = [
                                        800  => '800 từ',
                                        1200 => '1200 từ',
                                        1500 => '1500 từ',
                                        2000 => '2000 từ',
                                        3000 => '3000 từ',
                                        3500 => '3000+ từ'
                                    ];
                                    $has_valid_option = false;
                                    foreach ($word_options as $val => $label) {
                                        if ($val >= $f_min_words && $val <= $f_max_words) {
                                            $selected = ($val == 1200) ? 'selected' : '';
                                        echo '<option value="' . esc_attr($val) . '" ' . esc_attr($selected) . '>' . esc_html($label) . '</option>';
                                            $has_valid_option = true;
                                        }
                                    }
                                    // Fallback if current options are out of plan
                                    if (!$has_valid_option) {
                                        echo '<option value="' . esc_attr($f_max_words) . '" selected>' . esc_html($f_max_words) . ' từ (Max Plan)</option>';
                                    }
                                    ?>
                                </select>
                                <?php if ($f_max_words < 3500): ?>
                                    <!-- <small class="help-text">Giới hạn gói: <?php echo esc_html($f_min_words) . ' - ' . esc_html($f_max_words); ?> từ.</small> -->

                                <?php endif; ?>
                            </div>

                            <!-- 5. DEFAULT AUDIENCE -->
                            <div class="form-group">
                                <label class="eonsr-aeo-agent-label">Đối tượng mặc định</label>
                                <select id="audience_select_bulk" class="eonsr-aeo-agent-select full-width" onchange="updateAudienceInputBulk(this)">
                                    <option value="General Audience" selected>General Audience (Đại chúng)</option>
                                    <option value="Beginners & Novices">Beginners (Người mới bắt đầu)</option>
                                    <option value="Professionals & Experts">Professionals (Chuyên gia/Có kinh nghiệm)</option>
                                    <option value="Business Owners">Business Owners (Chủ doanh nghiệp)</option>
                                    <option value="Potential Customers">Potential Customers (Khách hàng tiềm năng)</option>
                                    <option value="custom" style="font-weight:bold; color:#2271b1;">-- Tự nhập (Khác) --</option>
                                </select>

                                <input type="text" 
                                    id="audience_real_input_bulk" 
                                    name="audience" 
                                    value="General Audience" 
                                    class="eonsr-aeo-agent-input full-width" 
                                    style="display: none; margin-top: 8px;" 
                                    placeholder="Nhập đối tượng cụ thể">
                                    
                                <small class="help-text">Dùng khi XLSX thiếu cột audience</small>
                            </div>

                            <!-- 6. OPTIONS (KEYWORDS, YOUTUBE, TRANSLATION) -->
                            <div class="form-group checkboxes">
                                <label class="checkbox-label">
                                    <input type="checkbox" name="gen_keywords" value="1" checked> 
                                    <span class="checkbox-text">Tự động tạo từ khóa</span>
                                </label>
                                
                                <!-- <label class="checkbox-label">
                                    <input type="checkbox" name="gen_youtube" value="1" <?php echo $f_allow_yt ? '' : 'disabled'; ?>> 
                                    <span class="checkbox-text">Embed YouTube <?php if (!$f_allow_yt) echo ' (🔒 Basic Plan)'; ?></span>
                                </label> -->

                                <!-- Updated Nonce Name -->
                                <?php wp_nonce_field('eonsr_aeo_agent_publish','eonsr_aeo_agent_publish_nonce'); ?>
                                
                                <!-- Auto Translate Option -->
                                <?php if ( count($saved_langs) > 1 ) : 
                                    $can_translate = ($f_langs_limit > 1);
                                ?>
                                    <!-- <label class="checkbox-label" style="margin-top: 5px;">
                                        <input type="checkbox" id="aeo_bulk_auto_translate" name="auto_translate" value="1" <?php echo $can_translate ? '' : 'disabled'; ?>>
                                        <span class="checkbox-text" <?php echo $can_translate ? '' : 'style="color:#999"'; ?>>
                                            <span class="dashicons dashicons-translation"></span>
                                            Dịch đa ngữ <?php if (!$can_translate) echo ' (🔒 Upgrade)'; ?>
                                        </span>
                                    </label> -->
                                    
                                    <div id="aeo_bulk_translation_options" style="display:none; margin-top: 5px; padding: 10px; background: #f0f6fc; border: 1px solid #c5d7ed; border-radius: 4px; margin-left: 25px;">
                                        <p style="margin:0 0 8px; font-size:12px; font-weight:600; color:#1d2327;">Chọn ngôn ngữ đích:</p>
                                        
                                        <div id="aeo_bulk_lang_list" style="max-height: 150px; overflow-y: auto;">
                                            <?php 
                                            foreach ($saved_langs as $lang_code) {
                                                $l_data  = isset($all_languages[$lang_code]) ? $all_languages[$lang_code] : null;
                                                $l_label = is_array($l_data) ? $l_data['flag'] . ' ' . $l_data['name'] : $lang_code;
                                                
                                                echo '<label class="checkbox-label" style="margin-bottom:5px; display:flex; align-items:center;">';
                                                echo '<input type="checkbox" name="eonsr_aeo_target_langs[]" value="'.esc_attr($lang_code).'"> '; // Updated field name
                                                echo '<span class="checkbox-text" style="margin-left:5px;">' . esc_html($l_label) . '</span>';
                                                echo '</label>';
                                            }
                                            ?>
                                        </div>
                                    </div>
                                <?php endif; ?>
                            </div>

                            <!-- 7. CUSTOM LOGO -->
                            <div style="margin-top: 15px; border-top: 1px dashed #ccc; padding-top: 10px; width: 100%;">
                                <!-- <label class="checkbox-label" style="display:flex; align-items:center;">
                                    <input type="checkbox" id="use_custom_logo" name="use_custom_logo" 
                                        <?php echo $use_logo ? 'checked' : ''; ?>
                                        <?php echo $allow_logo ? '' : 'disabled'; ?>>
                                    <span class="checkbox-text" <?php echo $allow_logo ? '' : 'style="color:#999"'; ?>>
                                        Thêm Logo vào ảnh <?php if (!$allow_logo) echo ' (🔒 Tính năng mở rộng)'; ?>
                                    </span>
                                </label> -->

                                <?php if ($allow_logo): ?>
                                    <div id="aeo-logo-upload-area" style="margin-top:10px; margin-left:25px; <?php echo $use_logo ? '' : 'display:none;'; ?>">
                                        <div style="display:flex; align-items:center; gap:10px;">
                                            <div id="aeo-logo-preview" style="width:50px; height:50px; border:1px dashed #ccc; display:flex; align-items:center; justify-content:center; background:#f9f9f9; overflow:hidden; border-radius:4px;">
                                                <?php if ($current_logo_url): ?>
                                                    <img src="<?php echo esc_url($current_logo_url); ?>" style="max-width:100%; max-height:100%;">
                                                <?php else: ?>
                                                    <span class="dashicons dashicons-format-image" style="color:#ccc"></span>
                                                <?php endif; ?>
                                            </div>
                                            <div>
                                                <button type="button" class="button button-small" id="btn-upload-logo">Tải logo (PNG)</button>
                                                <button type="button" class="button button-small button-link-delete" id="btn-remove-logo" <?php echo $current_logo_url ? '' : 'style="display:none"'; ?>>Xóa</button>
                                                <input type="file" id="aeo-logo-file" accept="image/png" style="display:none;">
                                            </div>
                                        </div>
                                        <small style="display:block; margin-top:5px; color:#666; font-size:11px;">Logo sẽ được chèn vào góc ảnh khi tạo bulk.</small>
                                    </div>
                                <?php endif; ?>
                            </div>

                            <!-- 8. FILE UPLOAD AREA -->
                            <div class="form-group file-upload-area">
                                <label for="bulk_csv_file_input" class="file-upload-label">
                                    📂 Chọn file XLSX
                                </label>
                                <input type="file" id="bulk_csv_file_input" name="bulk_csv_file" accept=".xlsx" required>
                                <div id="file-name-display">Chưa chọn file</div>
                            </div>

                            <div class="form-actions">
                                <!-- Updated Button ID -->
                                <button type="submit" class="button button-primary button-hero full-width" id="aeo-bulk-submit-btn" disabled>
                                    📤 Upload và Bắt đầu
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- [COL RIGHT] STATUS & HISTORY -->
            <div class="eonsr-aeo-col-right">
                
                <!-- Status Card -->
                <div class="eonsr-aeo-card status-card">
                    <div class="eonsr-aeo-card-header">
                        <h2>📊 Trạng thái xử lý</h2>
                    </div>
                    <div class="eonsr-aeo-card-body">
                        <div id="aeo-agent-bulk-status">
                            <div class="aeo-empty-state">
                                <span class="dashicons dashicons-clock"></span>
                                <p>Hệ thống đang chờ tác vụ mới...</p>
                            </div>
                        </div>
                        
                        <div id="aeo-agent-bulk-details" style="display: none;">
                            <hr>
                            <div id="aeo-agent-bulk-jobs-list" class="aeo-scrollable-list"></div>
                        </div>
                    </div>
                </div>

                <!-- History Card -->
                <div class="eonsr-aeo-card history-card">
                    <div class="eonsr-aeo-card-header flex-header">
                        <div class="header-title-group">
                            <h2>📜 Lịch sử Upload</h2>
                            <span class="header-count" id="history-total-count">0 files</span>
                        </div>
                        
                        <div class="header-tools">
                            <!-- Search -->
                            <div class="aeo-search-wrapper">
                                <span class="dashicons dashicons-search"></span>
                                <input type="text" id="history-search-input" placeholder="Tìm tên file...">
                            </div>

                            <!-- Actions -->
                            <div class="tool-actions">
                                <button type="button" class="button button-icon" id="refresh-history-btn" title="Làm mới">
                                    <span class="dashicons dashicons-update"></span>
                                </button>
                                <button type="button" class="button button-icon delete-all" id="clear-all-history-btn" title="Xóa toàn bộ lịch sử">
                                    <span class="dashicons dashicons-trash"></span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <div class="eonsr-aeo-card-body p-0">
                        <div class="aeo-table-responsive">
                            <table class="aeo-custom-table">
                                <thead>
                                    <tr>
                                        <th width="20%">Thời gian</th>
                                        <th width="25%">Tên File</th>
                                        <th width="15%">Bulk ID</th>
                                        <th width="10%" class="text-center">SL</th>
                                        <th width="15%">Trạng thái</th>
                                        <th width="15%" class="text-right">Hành động</th>
                                    </tr>
                                </thead>
                                <tbody id="aeo-bulk-history-body">
                                    <tr><td colspan="6">Đang tải dữ liệu...</td></tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Pagination -->
                        <div id="aeo-history-pagination" class="aeo-pagination-bar"></div>
                    </div>
                </div>

            </div> <!-- End Right Col -->
        </div> <!-- End Grid -->
    </div> <!-- End Wrap -->
    <?php
}