<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : import-modal-tpl.php
 * @location     : /modules/components/import-modal-tpl.php
 * @type         : Component
 * @scope        : Cross-Module
 * @allowed      : Modal rendering, import functionality
 * @reusability  : Shared
 * @notes        : Dynamic import 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'];
?>

<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>Import <?php echo esc_html($plural); ?></h3>
            <button class="igny8-btn-close" onclick="igny8CloseImportExportModal()">&times;</button>
        </div>
        <div class="igny8-modal-body">
            <p>Import <?php echo esc_html(strtolower($plural)); ?> from a CSV file. Use the template below for proper format.</p>
            
            <!-- Template Download -->
            <div class="igny8-mb-15">
                <button type="button" class="igny8-btn igny8-btn-outline" onclick="igny8DownloadTemplate('<?php echo esc_attr($table_id); ?>')">
                    <span class="dashicons dashicons-download"></span> Download <?php echo esc_html($singular); ?> Template
                </button>
            </div>
            
            <!-- Import Form -->
            <form id="igny8-modal-import-form" enctype="multipart/form-data">
                <input type="hidden" name="action" value="igny8_run_import">
                <input type="hidden" name="nonce" value="">
                <input type="hidden" name="import_type" value="<?php echo esc_attr($config['type']); ?>">
                
                <div class="igny8-form-group">
                    <label for="import-file">Select CSV File</label>
                    <input type="file" id="import-file" name="import_file" accept=".csv" required>
                    <p class="description">Upload a CSV file with your <?php echo esc_html(strtolower($plural)); ?>. Use the template above for proper format.</p>
                </div>
                
            </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-success" onclick="igny8SubmitImportForm()">
                <span class="dashicons dashicons-upload"></span> Import <?php echo esc_html($plural); ?>
            </button>
        </div>
    </div>
</div>
