<?php
/**
 * Onboarding wizard — single-page summary of the most important defaults.
 *
 * @package Brainwerk SEO Suite
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

$keys = array(
    'tracking_enabled', 'tracking_exclude_admins', 'tracking_exclude_bots',
    'privacy_anonymize_ip', 'seo_meta_enabled', 'seo_schema_enabled',
    'sitemap_enabled', 'log_404_enabled',
    'geo_llms_enabled', 'seo_schema_faq_enabled',
    'notify_email_to', 'notify_email_enabled',
    'intel_enabled',
);
?>
<div class="seoforge-card seoforge-onboarding">
    <h2>👋 <?php esc_html_e( 'Welcome to Brainwerk SEO Suite!', 'brainwerk-seo-suite' ); ?></h2>
    <p style="font-size:15px;"><?php esc_html_e( 'A few quick decisions and you\'re live. Don\'t worry — every option below can be changed later under Privacy, Meta, or Tools.', 'brainwerk-seo-suite' ); ?></p>
    <?php
    $competitor = Seoforge_Compat::competitor_label();
    if ( $competitor ) : ?>
    <div class="seoforge-callout seoforge-callout-info">
        <strong>🤝 <?php
            printf(
                /* translators: %s competitor plugin name */
                esc_html__( '%s is active.', 'brainwerk-seo-suite' ),
                esc_html( $competitor )
            );
        ?></strong>
        <p>
            <?php
            printf(
                /* translators: 1: competitor 2: link to import tab */
                esc_html__( 'Brainwerk SEO Suite will run as an analytics + 404 + redirect helper next to %1$s. When you\'re ready to switch fully, %2$s.', 'brainwerk-seo-suite' ),
                esc_html( $competitor ),
                '<a href="' . esc_url( admin_url( 'admin.php?page=brainwerk-seo-suite&tab=import' ) ) . '">' . esc_html__( 'use the one-click import wizard', 'brainwerk-seo-suite' ) . '</a>'
            );
            ?>
        </p>
    </div>
    <?php endif; ?>

    <form method="post" action="">
        <?php wp_nonce_field( Seoforge_Admin::NONCE ); ?>
        <input type="hidden" name="seoforge_action" value="save_settings">
        <input type="hidden" name="seoforge_onboarding_done" value="1">
        <?php foreach ( $keys as $k ) : ?>
            <input type="hidden" name="seoforge_tab_keys[]" value="<?php echo esc_attr( $k ); ?>">
        <?php endforeach; ?>

        <ol class="seoforge-stepper">
            <li>
                <h3><?php esc_html_e( 'Track visitors', 'brainwerk-seo-suite' ); ?></h3>
                <p><?php esc_html_e( 'Local, server-side analytics. No third-party services; only a first-party session cookie is used.', 'brainwerk-seo-suite' ); ?></p>
                <label class="seoforge-switch">
                    <input type="checkbox" name="seoforge[tracking_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'tracking_enabled', true ) ); ?>>
                    <span></span>
                </label>
                <p>
                    <label><input type="checkbox" name="seoforge[tracking_exclude_admins]" value="1" <?php checked( Seoforge_Settings::get( 'tracking_exclude_admins', true ) ); ?>>
                        <?php esc_html_e( 'Don\'t track logged-in editors/admins', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[tracking_exclude_bots]" value="1" <?php checked( Seoforge_Settings::get( 'tracking_exclude_bots', true ) ); ?>>
                        <?php esc_html_e( 'Don\'t track bots', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[privacy_anonymize_ip]" value="1" <?php checked( Seoforge_Settings::get( 'privacy_anonymize_ip', true ) ); ?>>
                        <?php esc_html_e( 'Anonymize IPs (recommended)', 'brainwerk-seo-suite' ); ?></label>
                </p>
            </li>
            <li>
                <h3><?php esc_html_e( 'Data retention on uninstall', 'brainwerk-seo-suite' ); ?></h3>
                <p><?php esc_html_e( 'If you ever delete this plugin, what should happen to the analytics data it has collected? Please choose — there is no default selection.', 'brainwerk-seo-suite' ); ?></p>
                <p>
                    <label style="display:block;margin-bottom:6px;">
                        <input type="radio" name="seoforge[delete_on_uninstall]" value="1" required>
                        <?php esc_html_e( 'Delete all analytics data when the plugin is uninstalled (recommended for data minimisation)', 'brainwerk-seo-suite' ); ?></label>
                    <label style="display:block;">
                        <input type="radio" name="seoforge[delete_on_uninstall]" value="0" required>
                        <?php esc_html_e( 'Keep the data on uninstall (e.g. for a later reinstall)', 'brainwerk-seo-suite' ); ?></label>
                </p>
            </li>
            <li>
                <h3><?php esc_html_e( 'SEO defaults', 'brainwerk-seo-suite' ); ?></h3>
                <p><?php esc_html_e( 'Manage <title>, meta description, OG tags and JSON-LD schema.', 'brainwerk-seo-suite' ); ?></p>
                <p>
                    <label><input type="checkbox" name="seoforge[seo_meta_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'seo_meta_enabled', true ) ); ?>>
                        <?php esc_html_e( 'Manage meta tags', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[seo_schema_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'seo_schema_enabled', true ) ); ?>>
                        <?php esc_html_e( 'Output JSON-LD schema', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[sitemap_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'sitemap_enabled', true ) ); ?>>
                        <?php esc_html_e( 'Generate XML sitemap', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[log_404_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'log_404_enabled', true ) ); ?>>
                        <?php esc_html_e( 'Log 404s', 'brainwerk-seo-suite' ); ?></label>
                </p>
            </li>
            <li>
                <h3><?php esc_html_e( 'AI search readiness (GEO/AEO)', 'brainwerk-seo-suite' ); ?></h3>
                <p><?php esc_html_e( 'Help AI answer engines (ChatGPT, Gemini, Perplexity…) find and cite your content correctly.', 'brainwerk-seo-suite' ); ?></p>
                <p>
                    <label><input type="checkbox" name="seoforge[geo_llms_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'geo_llms_enabled', false ) ); ?>>
                        <?php esc_html_e( 'Serve an llms.txt content manifest for AI crawlers', 'brainwerk-seo-suite' ); ?></label><br>
                    <label><input type="checkbox" name="seoforge[seo_schema_faq_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'seo_schema_faq_enabled', false ) ); ?>>
                        <?php esc_html_e( 'Output FAQ / answer-engine schema where available', 'brainwerk-seo-suite' ); ?></label>
                </p>
            </li>
            <li>
                <h3><?php esc_html_e( 'SEO benchmark network', 'brainwerk-seo-suite' ); ?></h3>
                <p><?php esc_html_e( 'Contribute one aggregate snapshot per day and see how your site compares to anonymised peers in your industry. This is on by default — untick the box below to switch it off, any time.', 'brainwerk-seo-suite' ); ?></p>
                <p>
                    <label><input type="checkbox" name="seoforge[intel_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'intel_enabled', true ) ); ?>>
                        <?php esc_html_e( 'Yes, contribute my anonymous, aggregate SEO stats to the benchmark network', 'brainwerk-seo-suite' ); ?></label>
                </p>
                <p class="description" style="max-width:60em;">
                    <?php esc_html_e( 'What is sent: totals, percentages, p75 Core Web Vitals, analyzer score trends, an hour/weekday traffic profile and AI-crawler visibility — the same kind of numbers on your dashboard, always aggregated over the whole day. Never a single visitor, IP or URL. Days with fewer than 50 pageviews (or too few analyzer/Core-Web-Vitals samples) send nothing at all, and crawler counts are only ever sent as coarse bands, never exact numbers — so this stays genuinely anonymous, no data-processing agreement needed. Data goes to the ShieldForge-Intel hub (shieldforge-intel.brainwerk.at, EU); saying yes here also registers this site with that hub, if it isn\'t registered yet, which transmits this site\'s web address as a one-time step (see Privacy / GDPR for details). You can turn this off any time under Tools → SEO network, where you can also review and send a snapshot manually.', 'brainwerk-seo-suite' ); ?>
                </p>
            </li>
            <li>
                <h3><?php esc_html_e( 'Where should reports go?', 'brainwerk-seo-suite' ); ?></h3>
                <p>
                    <input type="email" name="seoforge[notify_email_to]" value="<?php echo esc_attr( Seoforge_Settings::get( 'notify_email_to', get_option( 'admin_email' ) ) ); ?>" class="regular-text">
                </p>
                <p>
                    <label><input type="checkbox" name="seoforge[notify_email_enabled]" value="1" <?php checked( Seoforge_Settings::get( 'notify_email_enabled', false ) ); ?>>
                        <?php esc_html_e( 'Send weekly digest by email', 'brainwerk-seo-suite' ); ?></label>
                </p>
            </li>
        </ol>
        <?php submit_button( __( 'Save & finish setup', 'brainwerk-seo-suite' ), 'primary large' ); ?>
    </form>
</div>
