<?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 Orders -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Search Existing Order on your site based on...', 'primelink' ); ?></h3>
        </div>
        <div class="mt_primelink-card-body">
            <select id="mt_primelink-match-existing" class="widefat">
                <option value="order_id"><?php esc_html_e( 'Order ID', 'primelink' ); ?></option>
                <option value="customer_email"><?php esc_html_e( 'Customer Email', 'primelink' ); ?></option>
                <option value="billing_phone"><?php esc_html_e( 'Billing Phone', 'primelink' ); ?></option>
                <option value="transaction_id"><?php esc_html_e( 'Transaction ID', 'primelink' ); ?></option>
            </select>
            <p class="description">
                <?php esc_html_e( 'Choose how PrimeLink detects existing orders before updating.', 'primelink' ); ?>
            </p>
        </div>
    </section>

    <!-- Update Existing Orders -->
    <section class="mt_primelink-card mt_primelink-card--glass">
        <div class="mt_primelink-card-header">
            <h3><?php esc_html_e( 'Update Existing Order 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="status_total" />
                <?php esc_html_e( 'Update Status / Total 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="status" checked /> <?php esc_html_e( 'Order Status', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="total" checked /> <?php esc_html_e( 'Order Total', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="customer" checked /> <?php esc_html_e( 'Customer Data', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="items" checked /> <?php esc_html_e( 'Order Items', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="notes" checked /> <?php esc_html_e( 'Order Notes', 'primelink' ); ?></label><br/>
                <label><input type="checkbox" class="mt_primelink-update-field" value="custom_fields" checked /> <?php esc_html_e( 'Custom Fields', '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 Supplier 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>
