<?php
/**
 * Import Wizard - Step 6 (Import Options & Scheduling) for Downloads.
 *
 * @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 Downloads -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Search Existing Download on your site based on...', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">
            <select id="mt_primelink-match-existing" class="widefat">
                <option value="file_name"><?php esc_html_e( 'Product ID + File Name', 'primelink' ); ?></option>
                <option value="file_url"><?php esc_html_e( 'Product ID + File URL', 'primelink' ); ?></option>
                <option value="download_id"><?php esc_html_e( 'Product ID + Download ID', 'primelink' ); ?></option>
            </select>
            <p class="description">
                <?php esc_html_e( 'Choose how PrimeLink detects existing downloads before updating.', 'primelink' ); ?>
            </p>
        </div>
    </section>

    <!-- Update Existing Downloads -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Update Existing Download 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="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="name" checked /> <?php esc_html_e( 'File Name', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="url" checked /> <?php esc_html_e( 'File URL', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="limit" checked /> <?php esc_html_e( 'Download Limit', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="expiry" checked /> <?php esc_html_e( 'Download Expiry', 'primelink' ); ?></label><br/>
            </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 Download Feed', 'primelink' ); ?>" />
                </div>

                <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">
                    <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>

                <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>

