<?php
if (!defined('ABSPATH')) die('Restricted Access');
if (!current_user_can('manage_options')) {
    wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'ai-flash-tune'));
}
$aiflt_page_title = __('Setup Wizard', 'ai-flash-tune');
$setup = class_exists('AIFLT_World_Class_Tools') ? AIFLT_World_Class_Tools::get_setup_steps() : ['steps' => [], 'done' => 0, 'total' => 0, 'percent' => 0];
?>
<div class="ai-flash-tune-admin-wrapper">
    <?php include_once('ai-flash-tune-admin-sidebar.php'); ?>
    <div class="ai-flash-tune-main-content">
        <div class="ai-flash-tune-page-header ai-flash-tune-mb-8">
            <div>
                <span class="ai-flash-tune-main-title"><?php echo esc_html($aiflt_page_title); ?></span>
                <p class="ai-flash-tune-page-subtitle"><?php echo esc_html__('Complete these checks before relying on conversion insights or AI recommendations.', 'ai-flash-tune'); ?></p>
            </div>
        </div>

        <div class="aiflt-hero-card aiflt-setup-hero ai-flash-tune-mb-8">
            <div>
                <span class="aiflt-kicker"><?php echo esc_html__('Store readiness', 'ai-flash-tune'); ?></span>
                <h2><?php
                    /* translators: 1: completed setup steps, 2: total setup steps. */
                    echo esc_html(sprintf(__('%1$d of %2$d steps complete', 'ai-flash-tune'), intval($setup['done']), intval($setup['total'])));
                ?></h2>
                <p><?php echo esc_html__('AI Flash Tune works best after tracking, privacy, AI mode, and reporting basics are reviewed.', 'ai-flash-tune'); ?></p>
            </div>
            <div class="aiflt-progress-ring" style="--aiflt-progress: <?php echo esc_attr($setup['percent']); ?>%;" aria-label="<?php echo esc_attr($setup['percent']); ?>%">
                <span><?php echo esc_html($setup['percent']); ?>%</span>
            </div>
        </div>

        <div class="aiflt-world-grid aiflt-world-grid-2">
            <?php foreach ($setup['steps'] as $aiflt_key => $aiflt_step) : ?>
                <div class="ai-flash-tune-card aiflt-check-card <?php echo !empty($aiflt_step['complete']) ? esc_attr('is-complete') : esc_attr('needs-action'); ?>">
                    <div class="aiflt-check-icon"><i class="fas <?php echo !empty($aiflt_step['complete']) ? esc_attr('fa-check') : esc_attr('fa-circle'); ?>"></i></div>
                    <div class="aiflt-check-body">
                        <h3><?php echo esc_html($aiflt_step['label']); ?></h3>
                        <p><?php echo esc_html($aiflt_step['description']); ?></p>
                        <?php if (empty($aiflt_step['complete']) && !empty($aiflt_step['manual'])) : ?>
                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
                                <?php wp_nonce_field('aiflt_mark_setup_step'); ?>
                                <input type="hidden" name="action" value="aiflt_mark_setup_step" />
                                <input type="hidden" name="step" value="<?php echo esc_attr($aiflt_key); ?>" />
                                <button type="submit" class="ai-flash-tune-btn ai-flash-tune-btn-gray"><?php echo esc_html__('Mark reviewed', 'ai-flash-tune'); ?></button>
                            </form>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>

        <div class="ai-flash-tune-card ai-flash-tune-mt-8">
            <h3><?php echo esc_html__('Recommended manual tracking test', 'ai-flash-tune'); ?></h3>
            <ol class="aiflt-dev-checklist">
                <li><?php echo esc_html__('Open an incognito/private browser so you are not tracked as admin.', 'ai-flash-tune'); ?></li>
                <li><?php echo esc_html__('Visit a product page and wait a few seconds.', 'ai-flash-tune'); ?></li>
                <li><?php echo esc_html__('Add the product to cart, open the cart page, then open checkout.', 'ai-flash-tune'); ?></li>
                <li><?php echo esc_html__('Place a test order using a test payment method.', 'ai-flash-tune'); ?></li>
                <li><?php echo esc_html__('Refresh Dashboard, Funnel Analysis, Products, and Abandoned Carts to verify events.', 'ai-flash-tune'); ?></li>
            </ol>
        </div>
    </div>
</div>
