<?php
/**
 * Import Wizard - Step 6 (Import Options & Scheduling).
 *
 * @package PrimeLink
 */

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

$import_id = isset( $_GET['import_id'] ) ? absint( $_GET['import_id'] ) : 0;
?>

<div class="mt_primelink-step mt_primelink-import-step-6" data-import-id="<?php echo esc_attr( $import_id ); ?>">

    <!-- Match Existing Items -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <div>
                <h3><?php esc_html_e( 'Duplicate Detection', 'primelink' ); ?></h3>
                <p class="description" style="margin:4px 0 0;">
                    <?php esc_html_e( 'Configure how PrimeLink detects existing items before updating.', 'primelink' ); ?>
                </p>
            </div>
            <span class="mt_primelink-summary-pill"><?php esc_html_e( 'HOT', 'primelink' ); ?></span>
        </div>
        <div class="mt_primelink-card-body">
            <div class="mt_primelink-form-row">
                <label for="mt_primelink-duplicate-strategy"><?php esc_html_e( 'Matching Strategy', 'primelink' ); ?></label>
                <select id="mt_primelink-duplicate-strategy" class="widefat">
                    <option value="single"><?php esc_html_e( 'Single Field (Simple)', 'primelink' ); ?></option>
                    <option value="multiple"><?php esc_html_e( 'Multiple Fields', 'primelink' ); ?></option>
                    <option value="fuzzy"><?php esc_html_e( 'Fuzzy Matching (Similarity)', 'primelink' ); ?></option>
                    <option value="hybrid"><?php esc_html_e( 'Hybrid (Exact + Fuzzy)', 'primelink' ); ?></option>
                </select>
                <p class="description">
                    <?php esc_html_e( 'Single: Match by one field. Multiple: Match by several fields. Fuzzy: Find similar items. Hybrid: Try exact first, then fuzzy.', 'primelink' ); ?>
                </p>
            </div>

            <div id="mt_primelink-duplicate-single-wrap" class="mt_primelink-duplicate-strategy-wrap">
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-match-existing"><?php esc_html_e( 'Match by Field', 'primelink' ); ?></label>
                    <select id="mt_primelink-match-existing" class="widefat">
                        <option value="sku"><?php esc_html_e( 'SKU', 'primelink' ); ?></option>
                        <option value="title"><?php esc_html_e( 'Title', 'primelink' ); ?></option>
                        <option value="slug"><?php esc_html_e( 'Slug', 'primelink' ); ?></option>
                        <option value="post_id"><?php esc_html_e( 'Post ID', 'primelink' ); ?></option>
                    </select>
                </div>
            </div>

            <div id="mt_primelink-duplicate-multiple-wrap" class="mt_primelink-duplicate-strategy-wrap" style="display:none;">
                <div class="mt_primelink-form-row">
                    <label><?php esc_html_e( 'Match by Fields', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="sku" checked /> <?php esc_html_e( 'SKU', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="title" /> <?php esc_html_e( 'Title', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="slug" /> <?php esc_html_e( 'Slug', 'primelink' ); ?></label>
                </div>
                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-duplicate-require-all" />
                        <?php esc_html_e( 'Require all fields to match (AND logic)', 'primelink' ); ?>
                    </label>
                    <p class="description">
                        <?php esc_html_e( 'If unchecked, any field match is sufficient (OR logic).', 'primelink' ); ?>
                    </p>
                </div>
            </div>

            <div id="mt_primelink-duplicate-fuzzy-wrap" class="mt_primelink-duplicate-strategy-wrap" style="display:none;">
                <div class="mt_primelink-form-row">
                    <label><?php esc_html_e( 'Match by Fields', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="title" checked /> <?php esc_html_e( 'Title', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="sku" /> <?php esc_html_e( 'SKU', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="content" /> <?php esc_html_e( 'Content', 'primelink' ); ?></label>
                </div>
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-fuzzy-threshold"><?php esc_html_e( 'Similarity Threshold', 'primelink' ); ?></label>
                    <input type="number" id="mt_primelink-fuzzy-threshold" min="0" max="100" value="85" step="1" />
                    <span class="description">%</span>
                    <p class="description">
                        <?php esc_html_e( 'Minimum similarity percentage to consider a match (0-100). Higher = stricter matching.', 'primelink' ); ?>
                    </p>
                </div>
            </div>

            <div id="mt_primelink-duplicate-hybrid-wrap" class="mt_primelink-duplicate-strategy-wrap" style="display:none;">
                <div class="mt_primelink-form-row">
                    <label><?php esc_html_e( 'Match by Fields', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="sku" checked /> <?php esc_html_e( 'SKU', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="title" checked /> <?php esc_html_e( 'Title', 'primelink' ); ?></label>
                    <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-duplicate-field" value="slug" /> <?php esc_html_e( 'Slug', 'primelink' ); ?></label>
                </div>
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-hybrid-fuzzy-threshold"><?php esc_html_e( 'Fuzzy Similarity Threshold', 'primelink' ); ?></label>
                    <input type="number" id="mt_primelink-hybrid-fuzzy-threshold" min="0" max="100" value="85" step="1" />
                    <span class="description">%</span>
                    <p class="description">
                        <?php esc_html_e( 'Used when exact match fails. Minimum similarity for fuzzy fallback.', 'primelink' ); ?>
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Update Existing Items -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Update Existing Items Fields', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">

            <label class="mt_primelink-radio">
                <input type="radio" name="mt_primelink-update-mode" value="all" checked />
                <?php esc_html_e( 'Update all data', 'primelink' ); ?>
            </label>

            <label class="mt_primelink-radio">
                <input type="radio" name="mt_primelink-update-mode" value="price_stock" />
                <?php esc_html_e( 'Update Price / Stock Only', 'primelink' ); ?>
            </label>

            <label class="mt_primelink-radio">
                <input type="radio" name="mt_primelink-update-mode" value="choose" />
                <?php esc_html_e( 'Choose which data to update', 'primelink' ); ?>
            </label>

            <div id="mt_primelink-update-choose-wrap" style="display:none;margin-top:10px;">
                <label><input type="checkbox" class="mt_primelink-update-field" value="title" checked /> <?php esc_html_e( 'Title & Content', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="product_data" checked /> <?php esc_html_e( 'Product Data', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="images" checked /> <?php esc_html_e( 'Images', 'primelink' ); ?></label><br/>
                <?php if ( class_exists( 'WPSEO_Meta' ) || defined( 'WPSEO_VERSION' ) ) : ?>
                    <label><input type="checkbox" class="mt_primelink-update-field" value="yoast" checked /> <?php esc_html_e( 'Yoast SEO', 'primelink' ); ?></label><br/>
                <?php endif; ?>
                <label><input type="checkbox" class="mt_primelink-update-field" value="custom_fields" checked /> <?php esc_html_e( 'Custom Fields', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="taxonomies" checked /> <?php esc_html_e( 'Taxonomies', 'primelink' ); ?></label><br/>
            </div>

        </div>
    </section>

    <!-- Incremental Import & Smart Update -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <div>
                <h3><?php esc_html_e( 'Incremental Import & Smart Update', 'primelink' ); ?></h3>
                <p class="description" style="margin:4px 0 0;">
                    <?php esc_html_e( 'Only update items that have actually changed, saving time and preserving manual edits.', 'primelink' ); ?>
                </p>
            </div>
            <span class="mt_primelink-summary-pill"><?php esc_html_e( 'HOT', 'primelink' ); ?></span>
        </div>
        <div class="mt_primelink-card-body">

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-incremental-enabled" />
                <strong><?php esc_html_e( 'Enable Incremental Import', 'primelink' ); ?></strong>
            </label>

            <p class="description" style="margin-top:4px;">
                <?php esc_html_e( 'Skip updating items that haven\'t changed since last import. Uses hash comparison to detect changes.', 'primelink' ); ?>
            </p>

            <div id="mt_primelink-incremental-options" style="display:none;margin-top:12px;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);">

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-incremental-mode"><?php esc_html_e( 'Update Mode', 'primelink' ); ?></label>
                    <select id="mt_primelink-incremental-mode" class="widefat">
                        <option value="all"><?php esc_html_e( 'Update if any field changed', 'primelink' ); ?></option>
                        <option value="price_stock_only"><?php esc_html_e( 'Update only if price/stock changed', 'primelink' ); ?></option>
                        <option value="custom"><?php esc_html_e( 'Update only if selected fields changed', 'primelink' ); ?></option>
                    </select>
                    <p class="description">
                        <?php esc_html_e( 'Choose which changes trigger an update.', 'primelink' ); ?>
                    </p>
                </div>

                <div id="mt_primelink-incremental-fields-wrap" style="display:none;margin-top:10px;">
                    <label><?php esc_html_e( 'Track changes for these fields:', 'primelink' ); ?></label>
                    <div style="margin-top:6px;">
                        <label style="display:block;margin-bottom:4px;">
                            <input type="checkbox" class="mt_primelink-incremental-field" value="title" checked />
                            <?php esc_html_e( 'Title & Content', 'primelink' ); ?>
                        </label>
                        <label style="display:block;margin-bottom:4px;">
                            <input type="checkbox" class="mt_primelink-incremental-field" value="product_data" checked />
                            <?php esc_html_e( 'Product Data (price, stock, SKU, etc.)', 'primelink' ); ?>
                        </label>
                        <label style="display:block;margin-bottom:4px;">
                            <input type="checkbox" class="mt_primelink-incremental-field" value="images" />
                            <?php esc_html_e( 'Images', 'primelink' ); ?>
                        </label>
                        <label style="display:block;margin-bottom:4px;">
                            <input type="checkbox" class="mt_primelink-incremental-field" value="taxonomies" />
                            <?php esc_html_e( 'Categories & Tags', 'primelink' ); ?>
                        </label>
                    </div>
                    <p class="description" style="margin-top:6px;">
                        <?php esc_html_e( 'Only checked fields will be compared. Unchecked fields won\'t trigger updates.', 'primelink' ); ?>
                    </p>
                </div>

                <div class="mt_primelink-form-row" style="margin-top:12px;">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-incremental-skip-unchanged" />
                        <?php esc_html_e( 'Skip unchanged items completely', 'primelink' ); ?>
                    </label>
                    <p class="description">
                        <?php esc_html_e( 'If enabled, unchanged items won\'t be processed at all (faster). If disabled, they\'ll be marked as skipped in logs.', 'primelink' ); ?>
                    </p>
                </div>

            </div>

        </div>
    </section>

    <!-- Image Options -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Image Options', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-use-first-gallery-as-featured" />
                <strong><?php esc_html_e( 'Use first gallery image as featured image', 'primelink' ); ?></strong>
            </label>
            <p class="description" style="margin-top:4px;">
                <?php esc_html_e( 'If no featured image is mapped, automatically use the first image from the gallery (images field) as the featured image.', 'primelink' ); ?>
            </p>

        </div>
    </section>

    <!-- Test Mode & Validation -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <div>
                <h3><?php esc_html_e( 'Test Mode & Validation', 'primelink' ); ?></h3>
                <p class="description" style="margin:4px 0 0;">
                    <?php esc_html_e( 'Test your import configuration without making any changes to your database.', 'primelink' ); ?>
                </p>
            </div>
            <span class="mt_primelink-summary-pill"><?php esc_html_e( 'HOT', 'primelink' ); ?></span>
        </div>
        <div class="mt_primelink-card-body">

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-test-mode" />
                <strong><?php esc_html_e( 'Enable Test Mode (Dry Run)', 'primelink' ); ?></strong>
            </label>
            <p class="description" style="margin-top:4px;">
                <?php esc_html_e( 'When enabled, the import will simulate all operations without saving any data. Perfect for testing your configuration before running the actual import.', 'primelink' ); ?>
            </p>

            <div id="mt_primelink-test-mode-options" style="display:none;margin-top:12px;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);">

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-test-limit"><?php esc_html_e( 'Test Records Limit', 'primelink' ); ?></label>
                    <input type="number" id="mt_primelink-test-limit" min="1" max="1000" value="10" />
                    <p class="description">
                        <?php esc_html_e( 'Number of records to process in test mode (for faster testing).', 'primelink' ); ?>
                    </p>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-test-validate-required" checked />
                        <?php esc_html_e( 'Validate required fields', 'primelink' ); ?>
                    </label>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-test-validate-format" checked />
                        <?php esc_html_e( 'Validate data formats (email, URL, date, etc.)', 'primelink' ); ?>
                    </label>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-test-check-duplicates" checked />
                        <?php esc_html_e( 'Check for duplicate detection', 'primelink' ); ?>
                    </label>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-test-skip-unchanged" />
                        <?php esc_html_e( 'Simulate incremental import (skip unchanged items)', 'primelink' ); ?>
                    </label>
                </div>

                <div class="mt_primelink-form-row" style="margin-top:12px;">
                    <button type="button" class="button button-primary" id="mt_primelink-run-test-import">
                        <?php esc_html_e( 'Run Test Import', 'primelink' ); ?>
                    </button>
                    <p class="description" style="margin-top:4px;">
                        <?php esc_html_e( 'Click to run a test import and see validation results without making any changes.', 'primelink' ); ?>
                    </p>
                </div>

                <div id="mt_primelink-test-results" style="display:none;margin-top:16px;padding:12px;background:rgba(0,0,0,0.2);border-radius:4px;">
                    <h4 style="margin-top:0;"><?php esc_html_e( 'Test Results', 'primelink' ); ?></h4>
                    <div id="mt_primelink-test-results-content"></div>
                </div>

            </div>

        </div>
    </section>

    <!-- Advanced Options -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Advanced Options', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-speed-optimization" />
                <?php esc_html_e( 'Import Speed Optimization', 'primelink' ); ?>
            </label>

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-iterative-processing" checked />
                <?php esc_html_e( 'Iterative, Piece-by-Piece Processing', 'primelink' ); ?>
            </label>

            <div class="mt_primelink-form-row" style="margin-top:8px;">
                <label for="mt_primelink-iteration-size"><?php esc_html_e( 'Records per iteration', 'primelink' ); ?></label>
                <input type="number" id="mt_primelink-iteration-size" min="1" max="500" value="20" />
                <p class="description">
                    <?php esc_html_e( 'Default: process 20 records per iteration in background.', 'primelink' ); ?>
                </p>
            </div>

        </div>
    </section>

    <!-- Scheduling -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Automatic Scheduling with Background Import', 'primelink' ); ?></h3>
        </div>

        <div class="mt_primelink-card-body">

            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-enable-schedule" />
                <?php esc_html_e( 'Enable Background Import Schedule', 'primelink' ); ?>
            </label>

            <div id="mt_primelink-schedule-wrap" style="display:none;margin-top:10px;">

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-schedule-name"><?php esc_html_e( 'Friendly Name', 'primelink' ); ?></label>
                    <input type="text" id="mt_primelink-schedule-name" placeholder="<?php esc_attr_e( 'e.g. Daily Supplier Feed', 'primelink' ); ?>" />
                </div>

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-schedule-type"><?php esc_html_e( 'Schedule Type', 'primelink' ); ?></label>
                    <select id="mt_primelink-schedule-type" class="widefat">
                        <option value="preset"><?php esc_html_e( 'Preset Intervals', 'primelink' ); ?></option>
                        <option value="custom"><?php esc_html_e( 'Custom Cron Expression', 'primelink' ); ?></option>
                        <option value="advanced"><?php esc_html_e( 'Advanced Options', 'primelink' ); ?></option>
                    </select>
                </div>

                <!-- Preset Intervals -->
                <div id="mt_primelink-schedule-preset-wrap" class="mt_primelink-schedule-type-wrap">
                    <div class="mt_primelink-form-row">
                        <label for="mt_primelink-schedule-interval"><?php esc_html_e( 'Import Interval', 'primelink' ); ?></label>
                        <select id="mt_primelink-schedule-interval" class="widefat">
                            <option value="hourly"><?php esc_html_e( 'Hourly', 'primelink' ); ?></option>
                            <option value="twicedaily"><?php esc_html_e( 'Twice Daily', 'primelink' ); ?></option>
                            <option value="daily" selected><?php esc_html_e( 'Daily', 'primelink' ); ?></option>
                            <option value="weekly"><?php esc_html_e( 'Weekly', 'primelink' ); ?></option>
                            <option value="monthly"><?php esc_html_e( 'Monthly', 'primelink' ); ?></option>
                        </select>
                    </div>

                    <div class="mt_primelink-form-row" id="mt_primelink-schedule-weekly-options" style="display:none;">
                        <label><?php esc_html_e( 'Days of Week', 'primelink' ); ?></label>
                        <div style="display:grid;grid-template-columns:repeat(7, 1fr);gap:4px;margin-top:4px;">
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="1" /> <?php esc_html_e( 'Mon', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="2" /> <?php esc_html_e( 'Tue', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="3" /> <?php esc_html_e( 'Wed', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="4" /> <?php esc_html_e( 'Thu', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="5" /> <?php esc_html_e( 'Fri', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="6" /> <?php esc_html_e( 'Sat', 'primelink' ); ?></label>
                            <label class="mt_primelink-check"><input type="checkbox" class="mt_primelink-schedule-day" value="0" /> <?php esc_html_e( 'Sun', 'primelink' ); ?></label>
                        </div>
                        <p class="description"><?php esc_html_e( 'Select specific days. Leave all unchecked to use all days.', 'primelink' ); ?></p>
                    </div>

                    <div class="mt_primelink-form-row" id="mt_primelink-schedule-monthly-options" style="display:none;">
                        <label><?php esc_html_e( 'Days of Month', 'primelink' ); ?></label>
                        <input type="text" id="mt_primelink-schedule-month-days" placeholder="1,15,30" />
                        <p class="description"><?php esc_html_e( 'Comma-separated list (e.g. 1,15,30) or leave empty for first day of month.', 'primelink' ); ?></p>
                    </div>

                    <div class="mt_primelink-form-row">
                        <label for="mt_primelink-schedule-start"><?php esc_html_e( 'Start Time', 'primelink' ); ?></label>
                        <input type="time" id="mt_primelink-schedule-start" value="00:00" />
                        <p class="description">
                            <?php esc_html_e( 'Default: current time if left empty.', 'primelink' ); ?>
                        </p>
                    </div>
                </div>

                <!-- Custom Cron Expression -->
                <div id="mt_primelink-schedule-custom-wrap" class="mt_primelink-schedule-type-wrap" style="display:none;">
                    <div class="mt_primelink-form-row">
                        <label for="mt_primelink-schedule-cron"><?php esc_html_e( 'Cron Expression', 'primelink' ); ?></label>
                        <input type="text" id="mt_primelink-schedule-cron" placeholder="0 2 * * *" style="font-family:monospace;" />
                        <p class="description">
                            <?php esc_html_e( 'Format: minute hour day month weekday (e.g. "0 2 * * *" = daily at 2:00 AM).', 'primelink' ); ?>
                            <a href="https://crontab.guru/" target="_blank"><?php esc_html_e( 'Cron expression helper', 'primelink' ); ?></a>
                        </p>
                    </div>
                </div>

                <!-- Advanced Options -->
                <div id="mt_primelink-schedule-advanced-wrap" class="mt_primelink-schedule-type-wrap" style="display:none;">
                    <div class="mt_primelink-form-row">
                        <label><?php esc_html_e( 'Multiple Time Slots', 'primelink' ); ?></label>
                        <div id="mt_primelink-schedule-times-wrap">
                            <div class="mt_primelink-schedule-time-row" style="display:grid;grid-template-columns:1fr auto;gap:8px;margin-bottom:4px;">
                                <input type="time" class="mt_primelink-schedule-time-slot" value="00:00" />
                                <button type="button" class="button mt_primelink-schedule-time-remove" style="display:none;"><?php esc_html_e( 'Remove', 'primelink' ); ?></button>
                            </div>
                        </div>
                        <button type="button" class="button" id="mt_primelink-schedule-time-add" style="margin-top:4px;"><?php esc_html_e( 'Add Time Slot', 'primelink' ); ?></button>
                        <p class="description"><?php esc_html_e( 'Run import at multiple times per day.', 'primelink' ); ?></p>
                    </div>

                    <div class="mt_primelink-form-row">
                        <label><?php esc_html_e( 'Weekday Filter', 'primelink' ); ?></label>
                        <select id="mt_primelink-schedule-weekday-filter" class="widefat">
                            <option value=""><?php esc_html_e( 'All days', 'primelink' ); ?></option>
                            <option value="weekdays"><?php esc_html_e( 'Weekdays only (Mon-Fri)', 'primelink' ); ?></option>
                            <option value="weekends"><?php esc_html_e( 'Weekends only (Sat-Sun)', 'primelink' ); ?></option>
                        </select>
                    </div>
                </div>

                <!-- Common Advanced Options -->
                <div class="mt_primelink-form-row" style="margin-top:12px;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);">
                    <label for="mt_primelink-schedule-timezone"><?php esc_html_e( 'Timezone', 'primelink' ); ?></label>
                    <select id="mt_primelink-schedule-timezone" class="widefat">
                        <?php
                        $timezones = timezone_identifiers_list();
                        $wp_timezone = wp_timezone_string();
                        foreach ( $timezones as $tz ) {
                            $selected = ( $tz === $wp_timezone ) ? 'selected' : '';
                            echo '<option value="' . esc_attr( $tz ) . '" ' . $selected . '>' . esc_html( $tz ) . '</option>';
                        }
                        ?>
                    </select>
                    <p class="description"><?php esc_html_e( 'Timezone for scheduled times. Default: WooCommerce timezone.', 'primelink' ); ?></p>
                </div>

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-schedule-start-date"><?php esc_html_e( 'Start Date', 'primelink' ); ?></label>
                    <input type="date" id="mt_primelink-schedule-start-date" />
                    <p class="description"><?php esc_html_e( 'Optional: Schedule will start from this date. Leave empty to start immediately.', 'primelink' ); ?></p>
                </div>

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-schedule-end-date"><?php esc_html_e( 'End Date', 'primelink' ); ?></label>
                    <input type="date" id="mt_primelink-schedule-end-date" />
                    <p class="description"><?php esc_html_e( 'Optional: Schedule will stop after this date. Leave empty for no end date.', 'primelink' ); ?></p>
                </div>

                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-schedule-max-runs"><?php esc_html_e( 'Maximum Runs', 'primelink' ); ?></label>
                    <input type="number" id="mt_primelink-schedule-max-runs" min="1" placeholder="<?php esc_attr_e( 'Unlimited', 'primelink' ); ?>" />
                    <p class="description"><?php esc_html_e( 'Optional: Stop schedule after this many runs. Leave empty for unlimited.', 'primelink' ); ?></p>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-schedule-retry-failure" />
                        <?php esc_html_e( 'Retry on failure', 'primelink' ); ?>
                    </label>
                    <div id="mt_primelink-schedule-retry-options" style="display:none;margin-top:8px;margin-left:24px;">
                        <label for="mt_primelink-schedule-retry-attempts"><?php esc_html_e( 'Max retry attempts', 'primelink' ); ?></label>
                        <input type="number" id="mt_primelink-schedule-retry-attempts" min="1" max="10" value="3" style="width:80px;" />
                        <label for="mt_primelink-schedule-retry-delay" style="margin-left:12px;"><?php esc_html_e( 'Delay (minutes)', 'primelink' ); ?></label>
                        <input type="number" id="mt_primelink-schedule-retry-delay" min="1" value="30" style="width:80px;" />
                    </div>
                </div>

                <div class="mt_primelink-form-row">
                    <label class="mt_primelink-check">
                        <input type="checkbox" id="mt_primelink-schedule-pause-on-error" />
                        <?php esc_html_e( 'Pause schedule on error', 'primelink' ); ?>
                    </label>
                    <p class="description"><?php esc_html_e( 'Automatically pause schedule if import fails with errors.', 'primelink' ); ?></p>
                </div>

                <label class="mt_primelink-check" style="margin-top:8px;">
                    <input type="checkbox" id="mt_primelink-email-attachment" />
                    <?php esc_html_e( 'Send E-mail with attachment after import', 'primelink' ); ?>
                </label>

            </div>
        </div>
    </section>

    <!-- Per-import notifications -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Notifications (this import only)', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">
            <label class="mt_primelink-check">
                <input type="checkbox" id="mt_primelink-notify-override" />
                <?php esc_html_e( 'Use custom notification settings for this import', 'primelink' ); ?>
            </label>
            <div id="mt_primelink-notify-override-wrap" style="display:none;margin-top:10px;">
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-notify-email-override"><?php esc_html_e( 'Notify email', 'primelink' ); ?></label>
                    <input type="email" id="mt_primelink-notify-email-override" placeholder="<?php esc_attr_e( 'you@example.com', 'primelink' ); ?>" />
                </div>
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-notify-finish-override"><?php esc_html_e( 'Email template (finish)', 'primelink' ); ?></label>
                    <textarea id="mt_primelink-notify-finish-override" rows="3" placeholder="<?php esc_attr_e( 'Import #{import_id} finished. Status: {status}. Created: {created}, Updated: {updated}, Skipped: {skipped}, Errors: {errors}', 'primelink' ); ?>"></textarea>
                    <p class="description"><?php esc_html_e( 'Placeholders: {import_id}, {status}, {created}, {updated}, {skipped}, {errors}', 'primelink' ); ?></p>
                </div>
                <div class="mt_primelink-form-row">
                    <label for="mt_primelink-notify-error-override"><?php esc_html_e( 'Email template (error)', 'primelink' ); ?></label>
                    <textarea id="mt_primelink-notify-error-override" rows="3" placeholder="<?php esc_attr_e( 'Import #{import_id} finished with errors: {errors}', 'primelink' ); ?>"></textarea>
                </div>
            </div>
        </div>
    </section>

</div>
