<?php
/**
 * Onboarding tab: language picker + 5-step wizard.
 *
 * @package Brainwerk Security Suite
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$steps   = Shieldforge_Onboarding::steps();
$current = Shieldforge_Onboarding::current_step();
$keys    = array_keys( $steps );
$idx     = (int) array_search( $current, $keys, true );
$next    = isset( $keys[ $idx + 1 ] ) ? $keys[ $idx + 1 ] : 'done';
$prev    = isset( $keys[ $idx - 1 ] ) ? $keys[ $idx - 1 ] : '';
$t       = array( 'Shieldforge_Onboarding', 't' );
$current_locale = Shieldforge_Onboarding_I18n::current_locale();

if ( 'done' === $current ) {
    Shieldforge_Onboarding::mark_complete();
}
?>
<div class="shieldforge-card sf-onboarding" lang="<?php echo esc_attr( $current_locale ); ?>">
    <ol class="sf-onboarding-stepper">
        <?php foreach ( $keys as $i => $key ) : ?>
            <li class="<?php echo $key === $current ? 'is-current' : ( $i < $idx ? 'is-done' : '' ); ?>">
                <span class="sf-step-num"><?php echo (int) ( $i + 1 ); ?></span>
                <span class="sf-step-label"><?php echo esc_html( $steps[ $key ] ); ?></span>
            </li>
        <?php endforeach; ?>
    </ol>

    <?php if ( 'language' === $current ) : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'language_title' ) ); ?></h2>
        <p><?php echo esc_html( call_user_func( $t, 'language_intro' ) ); ?></p>

        <form method="post" action="">
            <?php wp_nonce_field( 'shieldforge_onboarding_lang' ); ?>
            <input type="hidden" name="shieldforge_onboarding_action" value="save_language">

            <div class="sf-locale-grid">
                <?php foreach ( Shieldforge_Onboarding_I18n::locales() as $code => $label ) : ?>
                    <label class="sf-locale-option <?php echo $code === $current_locale ? 'is-selected' : ''; ?>">
                        <input type="radio" name="shieldforge_locale" value="<?php echo esc_attr( $code ); ?>" <?php checked( $code, $current_locale ); ?>>
                        <span class="sf-locale-code"><?php echo esc_html( strtoupper( $code ) ); ?></span>
                        <span class="sf-locale-label"><?php echo esc_html( $label ); ?></span>
                    </label>
                <?php endforeach; ?>
            </div>

            <p style="margin-top:1.2em">
                <button type="submit" class="button button-primary"><?php echo esc_html( call_user_func( $t, 'continue_btn' ) ); ?></button>
            </p>
        </form>

    <?php elseif ( 'welcome' === $current ) : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'welcome_title' ) ); ?></h2>
        <p><?php echo esc_html( call_user_func( $t, 'welcome_intro' ) ); ?></p>
        <ul class="sf-checklist">
            <li><?php echo esc_html( call_user_func( $t, 'welcome_li_1' ) ); ?></li>
            <li><?php echo esc_html( call_user_func( $t, 'welcome_li_2' ) ); ?></li>
            <li><?php echo esc_html( call_user_func( $t, 'welcome_li_3' ) ); ?></li>
        </ul>

    <?php elseif ( 'privacy' === $current ) : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'privacy_title' ) ); ?></h2>
        <form method="post" action="">
            <?php wp_nonce_field( Shieldforge_Admin::NONCE ); ?>
            <input type="hidden" name="shieldforge_action" value="save_settings">
            <input type="hidden" name="shieldforge_tab_keys[]" value="privacy_anonymize_ip">
            <input type="hidden" name="shieldforge_tab_keys[]" value="privacy_pseudonym_users">
            <input type="hidden" name="shieldforge_tab_keys[]" value="log_retention_days">
            <p><label class="sf-toggle"><input type="checkbox" name="shieldforge[privacy_anonymize_ip]" value="1" <?php checked( Shieldforge_Settings::get( 'privacy_anonymize_ip', true ) ); ?>> <?php echo esc_html( call_user_func( $t, 'privacy_anon' ) ); ?></label></p>
            <p><label class="sf-toggle"><input type="checkbox" name="shieldforge[privacy_pseudonym_users]" value="1" <?php checked( Shieldforge_Settings::get( 'privacy_pseudonym_users', false ) ); ?>> <?php echo esc_html( call_user_func( $t, 'privacy_pseudonym' ) ); ?></label></p>
            <p><label><?php echo esc_html( call_user_func( $t, 'privacy_retention' ) ); ?> <input type="number" name="shieldforge[log_retention_days]" value="<?php echo esc_attr( Shieldforge_Settings::get( 'log_retention_days', 30 ) ); ?>" min="1" max="365" class="small-text"></label></p>
            <p><button type="submit" class="button button-primary"><?php echo esc_html( call_user_func( $t, 'save' ) ); ?></button></p>
        </form>

    <?php elseif ( 'login' === $current ) : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'login_title' ) ); ?></h2>
        <form method="post" action="">
            <?php wp_nonce_field( Shieldforge_Admin::NONCE ); ?>
            <input type="hidden" name="shieldforge_action" value="save_settings">
            <input type="hidden" name="shieldforge_tab_keys[]" value="bruteforce_enabled">
            <input type="hidden" name="shieldforge_tab_keys[]" value="bruteforce_threshold">
            <input type="hidden" name="shieldforge_tab_keys[]" value="bruteforce_lockout_min">
            <p><label class="sf-toggle"><input type="checkbox" name="shieldforge[bruteforce_enabled]" value="1" <?php checked( Shieldforge_Settings::get( 'bruteforce_enabled', true ) ); ?>> <?php echo esc_html( call_user_func( $t, 'login_enabled' ) ); ?></label></p>
            <p><label><?php echo esc_html( call_user_func( $t, 'login_threshold' ) ); ?> <input type="number" name="shieldforge[bruteforce_threshold]" value="<?php echo esc_attr( Shieldforge_Settings::get( 'bruteforce_threshold', 5 ) ); ?>" min="1" max="100" class="small-text"></label></p>
            <p><label><?php echo esc_html( call_user_func( $t, 'login_lockout' ) ); ?> <input type="number" name="shieldforge[bruteforce_lockout_min]" value="<?php echo esc_attr( Shieldforge_Settings::get( 'bruteforce_lockout_min', 30 ) ); ?>" min="1" max="1440" class="small-text"></label></p>
            <p><button type="submit" class="button button-primary"><?php echo esc_html( call_user_func( $t, 'save' ) ); ?></button></p>
        </form>

    <?php elseif ( 'notifications' === $current ) : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'notif_title' ) ); ?></h2>
        <form method="post" action="">
            <?php wp_nonce_field( Shieldforge_Admin::NONCE ); ?>
            <input type="hidden" name="shieldforge_action" value="save_settings">
            <input type="hidden" name="shieldforge_tab_keys[]" value="notify_email_enabled">
            <input type="hidden" name="shieldforge_tab_keys[]" value="notify_email_to">
            <input type="hidden" name="shieldforge_tab_keys[]" value="digest_enabled">
            <p><label class="sf-toggle"><input type="checkbox" name="shieldforge[notify_email_enabled]" value="1" <?php checked( Shieldforge_Settings::get( 'notify_email_enabled', true ) ); ?>> <?php echo esc_html( call_user_func( $t, 'notif_alerts' ) ); ?></label></p>
            <p><label><?php echo esc_html( call_user_func( $t, 'notif_recipient' ) ); ?> <input type="email" name="shieldforge[notify_email_to]" value="<?php echo esc_attr( Shieldforge_Settings::get( 'notify_email_to', get_option( 'admin_email' ) ) ); ?>" class="regular-text"></label></p>
            <p><label class="sf-toggle"><input type="checkbox" name="shieldforge[digest_enabled]" value="1" <?php checked( Shieldforge_Settings::get( 'digest_enabled', true ) ); ?>> <?php echo esc_html( call_user_func( $t, 'notif_digest' ) ); ?></label></p>
            <p><button type="submit" class="button button-primary"><?php echo esc_html( call_user_func( $t, 'save' ) ); ?></button></p>
        </form>

    <?php else : ?>
        <h2><?php echo esc_html( call_user_func( $t, 'done_title' ) ); ?></h2>
        <p><?php echo esc_html( call_user_func( $t, 'done_body' ) ); ?></p>
        <p><a class="button button-primary" href="<?php echo esc_url( Shieldforge_Admin::tab_url( 'dashboard' ) ); ?>"><?php echo esc_html( call_user_func( $t, 'done_btn' ) ); ?></a></p>
    <?php endif; ?>

    <?php if ( 'language' !== $current ) : ?>
        <p class="sf-onboarding-nav">
            <?php if ( $prev && 'language' !== $prev ) : ?>
                <a class="button" href="<?php echo esc_url( Shieldforge_Onboarding::step_url( $prev ) ); ?>">&larr; <?php echo esc_html( call_user_func( $t, 'back' ) ); ?></a>
            <?php endif; ?>
            <?php if ( 'done' !== $current ) : ?>
                <a class="button button-primary" href="<?php echo esc_url( Shieldforge_Onboarding::step_url( $next ) ); ?>"><?php echo esc_html( call_user_func( $t, 'next' ) ); ?> &rarr;</a>
            <?php endif; ?>
        </p>
    <?php endif; ?>
</div>
