<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : tasks.php
 * @location     : modules/writer/
 * @type         : Tasks Management Page
 * @scope        : Writer Module
 * @allowed      : Writing tasks management, queued content, and task workflow
 * @reusability  : Writer Module
 * @notes        : Configuration-driven tasks 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'] = 'tasks';
$GLOBALS['current_module'] = 'writer';

// 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 = 'writer_tasks';

?>
<div class="igny8-module-page">
    <div class="igny8-container">
        
        <!-- Tasks 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>Writing Tasks</h3>
                        <p class="igny8-card-subtitle">Manage your content writing tasks and workflow</p>
                    </div>
                    <div class="igny8-card-icon">
                        <span class="dashicons dashicons-clipboard 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' => 'writer',
                'submodule' => 'tasks',
                'ajaxUrl' => admin_url('admin-ajax.php'),
                'nonce' => wp_create_nonce('igny8_writer_settings'),
                'parseNonce' => wp_create_nonce('igny8_parse_content'),
                '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,
                'imageSettings' => [
                    'desktop_enabled' => get_option('igny8_desktop_enabled', '1') === '1',
                    'mobile_enabled' => get_option('igny8_mobile_enabled', '0') === '1',
                    'max_in_article_images' => intval(get_option('igny8_max_in_article_images', 1))
                ]
            ]);
            ?>
        </div>

    </div>
</div>
