<?php
/**
 * Setup Wizard - Preferences Step
 *
 * @package AI_Image_SEO
 * @since 1.0.0
 *
 * @var array $data Template data.
 */

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

$infyp_languages   = $data['languages'];
$infyp_wizard_data = $data['wizard_data'];
?>
<div class="infyp-wizard-step-content infyp-step-preferences">
    <h2 class="infyp-step-title"><?php esc_html_e( 'Set Your Preferences', 'infy-ai-image-seo-optimizer' ); ?></h2>
    <p class="infyp-step-description">
        <?php esc_html_e( 'Help us customize AI Image SEO for your needs. All fields are optional.', 'infy-ai-image-seo-optimizer' ); ?>
    </p>

    <form class="infyp-preferences-form" id="infyp-preferences-form">
        <div class="infyp-form-grid">
            <!-- Website Type -->
            <div class="infyp-form-group">
                <label for="infyp-website-type"><?php esc_html_e( 'What type of website is this?', 'infy-ai-image-seo-optimizer' ); ?></label>
                <select id="infyp-website-type" name="website_type" class="infyp-select">
                    <option value=""><?php esc_html_e( 'Select website type...', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="blog" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'blog' ); ?>><?php esc_html_e( 'Blog / Personal', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="ecommerce" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'ecommerce' ); ?>><?php esc_html_e( 'E-commerce / WooCommerce', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="portfolio" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'portfolio' ); ?>><?php esc_html_e( 'Portfolio / Photography', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="business" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'business' ); ?>><?php esc_html_e( 'Business / Corporate', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="news" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'news' ); ?>><?php esc_html_e( 'News / Media', 'infy-ai-image-seo-optimizer' ); ?></option>
                    <option value="other" <?php selected( $infyp_wizard_data['website_type'] ?? '', 'other' ); ?>><?php esc_html_e( 'Other', 'infy-ai-image-seo-optimizer' ); ?></option>
                </select>
                <span class="infyp-form-hint"><?php esc_html_e( 'Helps us provide better default prompts', 'infy-ai-image-seo-optimizer' ); ?></span>
            </div>

            <!-- Language -->
            <div class="infyp-form-group">
                <label for="infyp-language"><?php esc_html_e( 'Primary content language', 'infy-ai-image-seo-optimizer' ); ?></label>
                <select id="infyp-language" name="language" class="infyp-select">
                    <?php foreach ( $infyp_languages as $infyp_code => $infyp_name ) : ?>
                        <option value="<?php echo esc_attr( $infyp_code ); ?>" <?php selected( get_locale(), $infyp_code ); ?>>
                            <?php echo esc_html( $infyp_name ); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <span class="infyp-form-hint"><?php esc_html_e( 'AI will generate content in this language', 'infy-ai-image-seo-optimizer' ); ?></span>
            </div>

            <!-- Image Count Estimate -->
            <div class="infyp-form-group infyp-form-group-full">
                <label><?php esc_html_e( 'Estimated number of images you plan to optimize', 'infy-ai-image-seo-optimizer' ); ?></label>
                <div class="infyp-radio-group">
                    <label class="infyp-radio-card">
                        <input type="radio" name="image_count" value="small" <?php checked( $infyp_wizard_data['image_count'] ?? '', 'small' ); ?> />
                        <span class="infyp-radio-content">
                            <span class="infyp-radio-label"><?php esc_html_e( '1 - 100', 'infy-ai-image-seo-optimizer' ); ?></span>
                            <span class="infyp-radio-desc"><?php esc_html_e( 'Small library', 'infy-ai-image-seo-optimizer' ); ?></span>
                        </span>
                    </label>
                    <label class="infyp-radio-card">
                        <input type="radio" name="image_count" value="medium" <?php checked( $infyp_wizard_data['image_count'] ?? '', 'medium' ); ?> />
                        <span class="infyp-radio-content">
                            <span class="infyp-radio-label"><?php esc_html_e( '100 - 1,000', 'infy-ai-image-seo-optimizer' ); ?></span>
                            <span class="infyp-radio-desc"><?php esc_html_e( 'Medium library', 'infy-ai-image-seo-optimizer' ); ?></span>
                        </span>
                    </label>
                    <label class="infyp-radio-card">
                        <input type="radio" name="image_count" value="large" <?php checked( $infyp_wizard_data['image_count'] ?? '', 'large' ); ?> />
                        <span class="infyp-radio-content">
                            <span class="infyp-radio-label"><?php esc_html_e( '1,000 - 10,000', 'infy-ai-image-seo-optimizer' ); ?></span>
                            <span class="infyp-radio-desc"><?php esc_html_e( 'Large library', 'infy-ai-image-seo-optimizer' ); ?></span>
                        </span>
                    </label>
                    <label class="infyp-radio-card">
                        <input type="radio" name="image_count" value="enterprise" <?php checked( $infyp_wizard_data['image_count'] ?? '', 'enterprise' ); ?> />
                        <span class="infyp-radio-content">
                            <span class="infyp-radio-label"><?php esc_html_e( '10,000+', 'infy-ai-image-seo-optimizer' ); ?></span>
                            <span class="infyp-radio-desc"><?php esc_html_e( 'Enterprise', 'infy-ai-image-seo-optimizer' ); ?></span>
                        </span>
                    </label>
                </div>
                <span class="infyp-form-hint"><?php esc_html_e( 'Helps us recommend appropriate batch sizes', 'infy-ai-image-seo-optimizer' ); ?></span>
            </div>

            <!-- Newsletter & Telemetry Opt-in (uses current user's email) -->
            <?php
            $current_user = wp_get_current_user();
            $infyp_user_email   = $current_user->user_email;
            $infyp_user_name    = $current_user->display_name ?: $current_user->user_login;
            ?>
            <div class="infyp-form-group infyp-form-group-full">
                <label class="infyp-form-label"><?php esc_html_e( 'Stay Updated', 'infy-ai-image-seo-optimizer' ); ?></label>
                <div class="infyp-newsletter-optin">
                    <div class="infyp-toggle-wrapper infyp-toggle-newsletter">
                        <input type="checkbox" id="infyp-newsletter-consent" name="newsletter_consent" value="1" <?php checked( $infyp_wizard_data['newsletter_consent'] ?? false ); ?> />
                        <label for="infyp-newsletter-consent">
                            <span class="infyp-toggle-switch"></span>
                            <span class="infyp-toggle-label">
                                <span class="infyp-toggle-title"><?php esc_html_e( 'Subscribe for SGE Tips, Product updates and special Promotions', 'infy-ai-image-seo-optimizer' ); ?></span>
                                <span class="infyp-toggle-desc">
                                    <?php
                                    printf(
                                        /* translators: %s: User's email address */
                                        esc_html__( 'We\'ll send occasional updates to %s and collect basic site info to improve your plugin experience. Unsubscribe anytime.', 'infy-ai-image-seo-optimizer' ),
                                        '<strong>' . esc_html( $infyp_user_email ) . '</strong>'
                                    );
                                    ?>
                                    <a href="https://infypress.com/privacy/" target="_blank" rel="noopener" class="infyp-privacy-link"><?php esc_html_e( 'Read more about data collection in our Privacy Policy', 'infy-ai-image-seo-optimizer' ); ?></a>
                                </span>
                            </span>
                        </label>
                    </div>

                    <!-- Data Disclosure Panel -->
                    <div class="infyp-data-disclosure">
                        <button type="button" class="infyp-disclosure-trigger" aria-expanded="false">
                            <svg class="infyp-disclosure-icon" width="16" height="16" viewBox="0 0 16 16" fill="none">
                                <path d="M6 4L10 8L6 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                            </svg>
                            <?php esc_html_e( 'See what data we collect', 'infy-ai-image-seo-optimizer' ); ?>
                        </button>

                        <div class="infyp-disclosure-content" aria-hidden="true">
                            <div class="infyp-disclosure-inner">
                                <div class="infyp-disclosure-intro">
                                    <p><?php esc_html_e( 'This data helps us troubleshoot plugin and theme conflicts, so we can fix issues before they affect you.', 'infy-ai-image-seo-optimizer' ); ?></p>
                                    <p><?php esc_html_e( 'We never sell or share your data with third parties. It is used only for development purposes so image optimization stays a smooth experience.', 'infy-ai-image-seo-optimizer' ); ?></p>
                                </div>

                                <!-- Required: Account Info -->
                                <div class="infyp-disclosure-category">
                                    <div class="infyp-disclosure-category-header">
                                        <div class="infyp-disclosure-category-info">
                                            <span class="infyp-disclosure-category-title"><?php esc_html_e( 'Account Info', 'infy-ai-image-seo-optimizer' ); ?></span>
                                            <span class="infyp-disclosure-badge-required"><?php esc_html_e( 'Required', 'infy-ai-image-seo-optimizer' ); ?></span>
                                        </div>
                                    </div>
                                    <span class="infyp-disclosure-category-desc"><?php esc_html_e( 'Name and email address, needed for newsletter delivery.', 'infy-ai-image-seo-optimizer' ); ?></span>
                                </div>

                                <!-- Optional: Site Environment -->
                                <div class="infyp-disclosure-category">
                                    <div class="infyp-disclosure-category-header">
                                        <div class="infyp-toggle-compact">
                                            <input type="checkbox" id="infyp-telemetry-environment" name="telemetry_environment" value="1" checked />
                                            <label for="infyp-telemetry-environment">
                                                <span class="infyp-toggle-compact-switch"></span>
                                            </label>
                                        </div>
                                        <span class="infyp-disclosure-category-title"><?php esc_html_e( 'Site Environment', 'infy-ai-image-seo-optimizer' ); ?></span>
                                    </div>
                                    <span class="infyp-disclosure-category-desc"><?php esc_html_e( 'WP, PHP, and MySQL versions, server software, memory limit, and debug mode. Helps us reproduce and fix compatibility issues.', 'infy-ai-image-seo-optimizer' ); ?></span>
                                </div>

                                <!-- Optional: Theme Info -->
                                <div class="infyp-disclosure-category">
                                    <div class="infyp-disclosure-category-header">
                                        <div class="infyp-toggle-compact">
                                            <input type="checkbox" id="infyp-telemetry-theme" name="telemetry_theme" value="1" checked />
                                            <label for="infyp-telemetry-theme">
                                                <span class="infyp-toggle-compact-switch"></span>
                                            </label>
                                        </div>
                                        <span class="infyp-disclosure-category-title"><?php esc_html_e( 'Theme Info', 'infy-ai-image-seo-optimizer' ); ?></span>
                                    </div>
                                    <span class="infyp-disclosure-category-desc"><?php esc_html_e( 'Theme name, version, and parent theme. Helps us identify theme-specific layout conflicts.', 'infy-ai-image-seo-optimizer' ); ?></span>
                                </div>

                                <!-- Optional: Content Overview -->
                                <div class="infyp-disclosure-category">
                                    <div class="infyp-disclosure-category-header">
                                        <div class="infyp-toggle-compact">
                                            <input type="checkbox" id="infyp-telemetry-content" name="telemetry_content" value="1" checked />
                                            <label for="infyp-telemetry-content">
                                                <span class="infyp-toggle-compact-switch"></span>
                                            </label>
                                        </div>
                                        <span class="infyp-disclosure-category-title"><?php esc_html_e( 'Content Overview', 'infy-ai-image-seo-optimizer' ); ?></span>
                                    </div>
                                    <span class="infyp-disclosure-category-desc"><?php esc_html_e( 'Media, image, post, page, and product counts. Helps us optimize batch processing for libraries of your size.', 'infy-ai-image-seo-optimizer' ); ?></span>
                                </div>

                                <!-- Optional: Plugin Detection -->
                                <div class="infyp-disclosure-category">
                                    <div class="infyp-disclosure-category-header">
                                        <div class="infyp-toggle-compact">
                                            <input type="checkbox" id="infyp-telemetry-plugins" name="telemetry_plugins" value="1" checked />
                                            <label for="infyp-telemetry-plugins">
                                                <span class="infyp-toggle-compact-switch"></span>
                                            </label>
                                        </div>
                                        <span class="infyp-disclosure-category-title"><?php esc_html_e( 'Plugin Detection', 'infy-ai-image-seo-optimizer' ); ?></span>
                                    </div>
                                    <span class="infyp-disclosure-category-desc"><?php esc_html_e( 'Plugin compatibility flags and lists. Helps us ensure compatibility with WooCommerce, Yoast, Rank Math, Elementor, and others.', 'infy-ai-image-seo-optimizer' ); ?></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Hidden fields for user data -->
                    <input type="hidden" name="user_email" value="<?php echo esc_attr( $infyp_user_email ); ?>" />
                    <input type="hidden" name="user_name" value="<?php echo esc_attr( $infyp_user_name ); ?>" />
                    <input type="hidden" name="user_id" value="<?php echo esc_attr( $current_user->ID ); ?>" />
                </div>
            </div>
        </div>
    </form>
</div>
