<?php
/**
 * General Settings Tab
 *
 * @package Spin_Wheel
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

// Variables in this template are scoped to the including render method (not truly
// global); the plugin's established "swp" prefix is part of its data schema and hook API.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
?>

<div class="swp-settings-section">
    <div class="swp-card">
        <div class="swp-card-body">

            <!-- Wheel Type -->
            <div class="swp-form-row">
                <?php
                swp_admin_field_label(
                    'swp_wheel_type',
                    __('Wheel Type', 'spin-wheel'),
                    __('Select the visual layout of the spin wheel shown to visitors.', 'spin-wheel')
                );
                ?>
                <div class="swp-input-wrapper">
                    <select name="swp_wheel_type" id="swp_wheel_type" class="swp-select swp-trigger-preview">
                        <option value="big_wheel" <?php selected($wheel_type, 'big_wheel'); ?>>
                            <?php esc_html_e('Big Wheel (Lucky Wheel)', 'spin-wheel'); ?>
                        </option>
                        <option value="nine_squares" <?php selected($wheel_type, 'nine_squares'); ?>>
                            <?php esc_html_e('N Squares', 'spin-wheel'); ?>
                        </option>
                    </select>
                </div>
            </div>

            <!-- Wheel Mode -->
            <div class="swp-form-row">
                <?php
                swp_admin_field_label(
                    'swp_wheel_mode',
                    __('Wheel Mode', 'spin-wheel'),
                    __('Instant Win: users receive prizes automatically.', 'spin-wheel'),
                    false
                );
                ?>
                <div class="swp-input-wrapper">
                    <select name="swp_wheel_mode" id="swp_wheel_mode" class="swp-select">
                        <option value="instant" <?php selected($wheel_mode, 'instant'); ?>>
                            <?php esc_html_e('⚡ Instant Win (Prizes Given Immediately)', 'spin-wheel'); ?>
                        </option>
                        <?php
                        /**
                         * Pro injects the Event Mode <option> here when the Spin Wheel Pro
                         * add-on is active.
                         *
                         * @param string $wheel_mode Currently selected wheel mode.
                         */
                        do_action('swp_wheel_mode_option', $wheel_mode);
                        ?>
                    </select>
                </div>
            </div>

            <!-- Prize Representation -->
            <div class="swp-form-row">
                <?php
                swp_admin_field_label(
                    'swp_prize_representation',
                    __('Prize Representation', 'spin-wheel'),
                    __('Choose how prizes should be displayed on the wheel: text labels, images, or both.', 'spin-wheel'),
                    true
                );
                ?>
                <div class="swp-input-wrapper">
                    <select name="swp_settings[prize_representation]" id="swp_prize_representation"
                        class="swp-select swp-trigger-preview">
                        <option value="label" <?php selected(isset($settings['prize_representation']) ? $settings['prize_representation'] : 'label', 'label'); ?>>
                            <?php esc_html_e('Label Only', 'spin-wheel'); ?>
                        </option>
                        <?php
                        /**
                         * Pro injects the Image / Both prize-representation options here
                         * when the Spin Wheel Pro add-on is active.
                         *
                         * @param string $current Currently selected prize representation.
                         */
                        do_action('swp_prize_representation_options', isset($settings['prize_representation']) ? $settings['prize_representation'] : 'label');
                        ?>
                    </select>
                </div>
            </div>

            <!-- Entry Restrictions + Participant Limit (Pro) -->
            <?php
            /**
             * Pro renders the per-wheel Entry Restrictions and Maximum Participants
             * controls here when the Spin Wheel Pro add-on is active.
             *
             * @param array $settings Per-wheel settings.
             * @param int   $wheel_id Wheel post ID.
             */
            do_action('swp_metabox_entry_restrictions', $settings, $wheel_id);
            do_action('swp_metabox_participant_limit', $settings, $wheel_id);
            ?>

            <!-- Email Notifications (Instant Mode Only) -->
            <div class="swp-form-row swp-instant-mode-only" style="<?php echo $wheel_mode !== 'instant' ? 'display: none;' : ''; ?>">
                <?php
                swp_admin_field_label(
                    '',
                    __('Winner Email Notifications', 'spin-wheel'),
                    __('Automatically send winner notification emails when users win prizes. You can configure the email template in Settings > Email.', 'spin-wheel')
                );
                ?>
                <div class="swp-input-wrapper">
                    <label class="swp-toggle-label">
                        <input type="checkbox" name="swp_settings[enable_winner_notifications]" value="1"
                            class="swp-toggle-input" <?php checked(isset($settings['enable_winner_notifications']) ? $settings['enable_winner_notifications'] : 1, 1); ?>>
                        <span class="swp-toggle-switch"></span>
                        <span class="swp-toggle-text"><?php esc_html_e('Enable winner emails', 'spin-wheel'); ?></span>
                    </label>
                </div>
            </div>

            <!-- Visual Effects -->
            <div class="swp-form-row">
                <?php
                swp_admin_field_label(
                    '',
                    __('Visual effects', 'spin-wheel'),
                    __('Confetti plays when the visitor wins. Auto-rotation slowly spins the wheel in the background until they interact.', 'spin-wheel')
                );
                ?>
                <div class="swp-input-wrapper">
                    <div class="swp-device-toggles">
                        <label class="swp-toggle-label">
                            <input type="checkbox" name="swp_settings[enable_confetti]" value="1"
                                class="swp-toggle-input" <?php checked(isset($settings['enable_confetti']) ? $settings['enable_confetti'] : 1, 1); ?>>
                            <span class="swp-toggle-switch"></span>
                            <span class="swp-toggle-text"><?php esc_html_e('Confetti on win', 'spin-wheel'); ?></span>
                        </label>

                        <label class="swp-toggle-label">
                            <input type="checkbox" name="swp_settings[enable_auto_rotation]" value="1"
                                class="swp-toggle-input" <?php checked(isset($settings['enable_auto_rotation']) ? $settings['enable_auto_rotation'] : 0, 1); ?>>
                            <span class="swp-toggle-switch"></span>
                            <span class="swp-toggle-text"><?php esc_html_e('Auto-rotation preview', 'spin-wheel'); ?></span>
                        </label>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>