<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : keywords.php
 * @location     : modules/planner/
 * @type         : Keywords Management Page
 * @scope        : Planner Module
 * @allowed      : Keywords research, import, analysis, and management
 * @reusability  : Planner Module
 * @notes        : Configuration-driven keywords management interface using complete component system
 * 
 * @package Igny8Compact
 * @since 1.0.0
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Set module variables
$GLOBALS['current_submodule'] = 'keywords';
$GLOBALS['current_module'] = 'planner';

// Load all required components
require_once plugin_dir_path(__FILE__) . '../../modules/components/filters-tpl.php';
require_once plugin_dir_path(__FILE__) . '../../modules/components/actions-tpl.php';
require_once plugin_dir_path(__FILE__) . '../../modules/components/table-tpl.php';
require_once plugin_dir_path(__FILE__) . '../../modules/components/pagination-tpl.php';

// Set table ID for components
$table_id = 'planner_keywords';

?>
<div class="igny8-module-page">
    <div class="igny8-container">
        
        <!-- Keywords Management Section -->
        <div class="igny8-dashboard-section">
            <div class="igny8-standard-header">
                <div class="igny8-card-header-content">
                    <div class="igny8-card-title-text">
                        <h3>Keywords Management</h3>
                        <p class="igny8-card-subtitle">Import, analyze, and organize your keywords</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-tag igny8-dashboard-icon-lg igny8-dashboard-icon-blue"></span>
                    </div>
                </div>
            </div>
            
            <!-- Complete Submodule Interface -->
            <?php
            // Render all components in correct order
            echo igny8_render_filters($table_id);
            echo igny8_render_table_actions($table_id);
            echo igny8_render_table($table_id);
            echo igny8_render_pagination($table_id);
            
            // Get cluster options for dropdowns
            $cluster_options = igny8_get_cluster_options();
            
            // Load filters configuration for JavaScript
            $filters_config = require plugin_dir_path(__FILE__) . '../../modules/config/filters-config.php';
            
            // Localize script for table initialization
            wp_localize_script('igny8-admin-js', 'IGNY8_PAGE', [
                'tableId' => $table_id,
                'module' => 'planner',
                'submodule' => 'keywords',
                'ajaxUrl' => admin_url('admin-ajax.php'),
                'nonce' => wp_create_nonce('igny8_planner_settings'),
                'defaultPerPage' => get_option('igny8_records_per_page', 20),
                'clusterOptions' => $cluster_options,
                'filtersConfig' => $filters_config,
                'cronKey' => igny8_needs_cron_functionality() ? igny8_get_or_generate_cron_key() : null
            ]);
            ?>
        </div>

    </div>
</div>
