<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : export-modal-tpl.php
 * @location     : /modules/components/export-modal-tpl.php
 * @type         : Component
 * @scope        : Cross-Module
 * @allowed      : Modal rendering, export functionality
 * @reusability  : Shared
 * @notes        : Dynamic export modal component for all modules
 */

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

// Get configuration for this table
$config = igny8_get_import_export_config($table_id);
if (!$config) {
    return;
}

$singular = $config['singular'];
$plural = $config['plural'];
$is_selected = !empty($selected_ids);
$mode_text = $is_selected ? "Selected {$plural}" : "All {$plural}";
?>

<div id="igny8-import-export-modal" class="igny8-modal" data-table-id="<?php echo esc_attr($table_id); ?>">
    <div class="igny8-modal-content">
        <div class="igny8-modal-header">
            <h3>Export <?php echo esc_html($mode_text); ?></h3>
            <button class="igny8-btn-close" onclick="igny8CloseImportExportModal()">&times;</button>
        </div>
        <div class="igny8-modal-body">
            <p>Export <?php echo esc_html(strtolower($mode_text)); ?> to CSV format.</p>
            
            <!-- Export Options -->
            <div class="igny8-form-group">
                <h4>Export Options</h4>
                <div class="igny8-checkbox-group">
                    <label class="igny8-checkbox-label">
                        <input type="checkbox" id="include-metrics" name="include_metrics" checked>
                        <span class="igny8-checkbox-text">Include Metrics</span>
                    </label>
                    <label class="igny8-checkbox-label">
                        <input type="checkbox" id="include-relationships" name="include_relationships">
                        <span class="igny8-checkbox-text">Include Relationships</span>
                    </label>
                    <label class="igny8-checkbox-label">
                        <input type="checkbox" id="include-timestamps" name="include_timestamps">
                        <span class="igny8-checkbox-text">Include Timestamps</span>
                    </label>
                </div>
            </div>
            
            <!-- Hidden form data -->
            <form id="igny8-modal-export-form" style="display: none;">
                <input type="hidden" name="action" value="<?php echo $is_selected ? 'igny8_export_selected' : 'igny8_run_export'; ?>">
                <input type="hidden" name="nonce" value="">
                <input type="hidden" name="export_type" value="<?php echo esc_attr($config['type']); ?>">
                <?php if ($is_selected): ?>
                    <input type="hidden" name="selected_ids" value="<?php echo esc_attr(json_encode($selected_ids)); ?>">
                <?php endif; ?>
            </form>
        </div>
        <div class="igny8-modal-footer">
            <button type="button" class="igny8-btn igny8-btn-secondary" onclick="igny8CloseImportExportModal()">Cancel</button>
            <button type="button" class="igny8-btn igny8-btn-primary" onclick="igny8SubmitExportForm()">
                <span class="dashicons dashicons-download"></span> Export <?php echo esc_html($mode_text); ?>
            </button>
        </div>
    </div>
</div>
