<?php
if (!defined('ABSPATH')) exit;

class AIIO_Onboarding {
    public static function init() {
        add_action('wp_ajax_aiio_complete_onboarding', [__CLASS__, 'ajax_complete']);
    }
    public static function is_done() {
        return !empty(aiio_get_settings()['onboarding_done']);
    }
    public static function render_modal() {
        if (self::is_done()) return;
        ?>
        <div id="aiio-onboarding" class="aiio-onboarding-modal" role="dialog" aria-modal="true">
            <div class="aiio-onboarding-backdrop"></div>
            <div class="aiio-onboarding-panel pewit-card">
                <h2><?php esc_html_e('Welcome to Pewit AI Image Optimizer', 'pewit-ai-image-optimizer'); ?></h2>
                <ol><li><?php esc_html_e('Run Scan on Dashboard to find heavy JPEG/PNG files.', 'pewit-ai-image-optimizer'); ?></li>
                <li><?php esc_html_e('Preview → Apply on a single image (Free).', 'pewit-ai-image-optimizer'); ?></li>
                <li><?php esc_html_e('Pro: bulk jobs, WebP sidecar, auto-optimize on upload.', 'pewit-ai-image-optimizer'); ?></li></ol>
                <p class="aiio-onboarding-actions">
                    <a class="pewit-btn pewit-btn-primary" href="<?php echo esc_url(aiio_admin_page_url('pewit-ai-image-optimizer-settings')); ?>"><?php esc_html_e('Settings', 'pewit-ai-image-optimizer'); ?></a>
                    <button type="button" class="button button-link" id="aiio-onboarding-dismiss"><?php esc_html_e('Skip', 'pewit-ai-image-optimizer'); ?></button>
                </p>
            </div>
        </div>
        <?php
    }
    public static function ajax_complete() {
        check_ajax_referer('aiio_nonce', 'nonce');
        if (!current_user_can('manage_options')) wp_send_json_error([], 403);
        $s = aiio_get_settings();
        $s['onboarding_done'] = 1;
        aiio_update_settings($s);
        wp_send_json_success();
    }
}
