<?php

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

/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://webequipe.com
 * @since      1.0.0
 *
 * @package    Webequipe_Spin_Win_Wheel
 * @subpackage Webequipe_Spin_Win_Wheel/admin/partials/tabs
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require __DIR__ . '/data-process.php'; ?>

 <div class="p-4 tabs-card-full wsww-general-tab">
     <div class="row d-flex align-items-stretch">

         <div class="col-lg-6 col-md-6 col-sm-12">
             <div class="card basic-card">
                 <div class="card-body">
                     <h5 class="card-title wsww-card-title mb-3">Basic Information</h5>
                     <div class="mb-3 wsww-form-row">
                         <label for="wsww-spin-title" class="form-label">Title</label>
                         <input id="wsww-spin-title" name="spin_title" type="text" class="form-control"
                             value="<?php echo esc_attr($spin->spin_title ?? ''); ?>" required>
                     </div>
                     <div class="mb-3 wsww-form-row">
                         <label for="wsww-spin-description" class="form-label">Description</label>
                         <textarea id="wsww-spin-description" name="spin_description" type="text" class="form-control"
                             rows="3"><?php echo esc_attr( $spin->spin_description); ?></textarea>
                     </div>

                     <h5 class="card-title wsww-card-subtitle mb-3">Status</h5>

                     <fieldset class="mb-3 wsww-status-section">
                         <legend class="screen-reader-text">Status</legend>
                         <div class="form-check mt-2">
                             <input class="form-check-input" type="radio" name="spin_status" id="wsww-status-active" value="active"
                                 <?php echo $spin->spin_status === 'active' ? 'checked' : ''; ?>>
                             <label class="form-check-label" for="wsww-status-active">
                                 Active
                             </label>
                         </div>
                         <div class="form-check">
                             <input class="form-check-input" type="radio" name="spin_status" id="wsww-status-inactive"
                                 value="inactive" <?php echo $spin->spin_status === 'inactive' ? 'checked' : ''; ?>>
                             <label class="form-check-label" for="wsww-status-inactive">
                                 Inactive
                             </label>
                         </div>
                     </fieldset>

                     <h5 class="card-title wsww-card-subtitle mb-3">CMS/Email Sync</h5>

                     <div class="mb-3">
                         <div class="wsww-sync-toggle">
                             <input class="wsww-sync-checkbox" type="checkbox" id="wsww-sync-enabled"
                                 name="sync_with_email_cms" value="1"
                                 <?php disabled( ! $wsww_sync_available ); ?>
                                 <?php checked( $wsww_sync_enabled ); ?>>
                             <label class="wsww-sync-label" for="wsww-sync-enabled">
                                 Sync responses with CMS/Email
                             </label>
                         </div>
                         <?php if ( ! $wsww_sync_available ) : ?>
                             <div class="wsww-sync-note" role="note" aria-live="polite">
                                 <p class="wsww-sync-note-title">
                                     <?php esc_html_e( 'Note: CMS/Email Sync needs an active CMS/Email API connection', 'webequipe-spin-win-wheel' ); ?>
                                 </p>
                                 <p class="wsww-sync-note-text">
                                     <?php esc_html_e( 'Please connect your CMS/Email API provider in settings before enabling sync for this wheel.', 'webequipe-spin-win-wheel' ); ?>
                                     <a class="wsww-sync-note-link" href="<?php echo esc_url( $wsww_mailchimp_settings_link ); ?>">
                                         <?php esc_html_e( 'Open CMS/Email API Settings', 'webequipe-spin-win-wheel' ); ?>
                                     </a>
                                 </p>
                             </div>
                         <?php endif; ?>
                     </div>

                     <div id="wsww-sync-settings-fields" <?php echo ( $wsww_sync_enabled && $wsww_sync_available ) ? '' : 'style="display:none;"'; ?>>
                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="wsww-sync-provider">CMS/Email Provider</label>
                         <select name="sync_provider" id="wsww-sync-provider" class="form-select">
                             <option value="mailchimp" <?php selected( $wsww_sync_provider, 'mailchimp' ); ?>>Mailchimp</option>
                             <option value="klaviyo" disabled>Klaviyo (Coming Soon)</option>
                             <option value="hubspot" disabled>HubSpot (Coming Soon)</option>
                             <option value="activecampaign" disabled>ActiveCampaign (Coming Soon)</option>
                         </select>
                     </div>

                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="wsww-sync-capture-mode">Capture Mode</label>
                         <select name="sync_capture_mode" id="wsww-sync-capture-mode" class="form-select">
                             <option value="both" <?php selected( $wsww_sync_capture_mode, 'both' ); ?>>Both (Win + Lose)</option>
                             <option value="win" <?php selected( $wsww_sync_capture_mode, 'win' ); ?>>Win only</option>
                             <option value="lose" <?php selected( $wsww_sync_capture_mode, 'lose' ); ?>>Lose only</option>
                         </select>
                     </div>
                     </div>
                 </div>
             </div>
         </div>

         <div class="col-lg-6 col-md-6 col-sm-12">
            <div class="card spin-setting-card">
                <div class="card-body">
                     <h5 class="card-title wsww-card-title mb-3">Spin Behavior Settings</h5>
                     <div class="mb-3 wsww-form-row wsww-spin-button-only">
                         <label class="form-label" for="wsww-initial-popup-delay">Initial Popup Delay</label>
                         <div class="input-group mb-3">
                             <input type="number" min="0" step="1" inputmode="numeric" id="wsww-initial-popup-delay" class="form-control"
                                 name="auto_minute" value="<?php echo esc_attr( $spin->auto_minute); ?>">
                             <span class="input-group-text">seconds</span>
                         </div>
                     </div>
                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="wsww-spin-duration">Wheel Spin Duration</label>
                         <div class="input-group mb-3">
                             <input type="number" min="0" step="1" inputmode="numeric" id="wsww-spin-duration" class="form-control" name="spin_duration"
                                 value="<?php echo esc_attr( $spin->spin_duration); ?>">
                             <span class="input-group-text">seconds</span>
                         </div>
                     </div>
                     <div class="mb-3 wsww-form-row wsww-spin-button-only">
                         <label class="form-label" for="wsww-reopen-delay">Reopen Delay</label>
                         <div class="input-group mb-3">
                             <input type="number" min="0" step="1" inputmode="numeric" id="wsww-reopen-delay" class="form-control" name="display_after"
                                 value="<?php echo esc_attr( $spin->display_after); ?>">
                             <span class="input-group-text">minutes</span>
                         </div>
                     </div>
                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="wsww-same-email-retry-delay">Retry Delay for Same Email</label>
                         <div class="input-group mb-3">
                             <input type="number" min="0" step="1" inputmode="numeric" id="wsww-same-email-retry-delay" class="form-control" name="display_after_same_email"
                                 value="<?php echo esc_attr( $spin->display_after_same_email); ?>">
                             <span class="input-group-text">minutes</span>
                         </div>
                     </div>
                </div>
             </div>
         </div>

         <div class="col-lg-6 col-md-6 col-sm-12">
             <div class="card spin-setting-card">
                 <div class="card-body">
                     <h5 class="card-title wsww-card-title mb-3">Spin Display Settings</h5>
                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="spin_type">Display Trigger</label>
                         <select name="spin_type" id="spin_type" class="form-select">
                             <option value="spin_button" class="spin_button" <?php echo $webequipe_sww_spin_spin_type === 'spin_button' ? 'selected' : ''; ?>>
                                 Button Click</option>
                             <option value="spin_auto" <?php echo $webequipe_sww_spin_spin_type === 'spin_auto' ? 'selected' : ''; ?>>Popup
                             </option>
                         </select>
                     </div>
                     
                     <fieldset class="mb-3 wsww-form-row">
                         <label for="displayLaptop" class="form-label">Responsive Display Settings</label>

                         <div class="form-check mt-2">
                             <input class="form-check-input" type="checkbox" name="spin_display_setting[]"
                                 id="displayLaptop" value="laptop"
                                 <?php echo in_array('laptop', $webequipe_sww_spin_display_settings) ? 'checked' : ''; ?>>
                             <label class="form-check-label" for="displayLaptop">
                                 Laptop
                             </label>
                         </div>

                         <div class="form-check">
                             <input class="form-check-input" type="checkbox" name="spin_display_setting[]"
                                 id="displayTablet" value="tablet"
                                 <?php echo in_array('tablet', $webequipe_sww_spin_display_settings) ? 'checked' : ''; ?>>
                             <label class="form-check-label" for="displayTablet">
                                 Tablet
                             </label>
                         </div>

                         <div class="form-check">
                             <input class="form-check-input" type="checkbox" name="spin_display_setting[]"
                                 id="displayMobile" value="mobile"
                                 <?php echo in_array('mobile', $webequipe_sww_spin_display_settings) ? 'checked' : ''; ?>>
                             <label class="form-check-label" for="displayMobile">
                                 Mobile
                             </label>
                         </div>
                     </fieldset>

                     <div class="mb-3 wsww-form-row">
                         <label class="form-label" for="wsww-spin-position">Wheel Position</label>
                         <select name="spin_position" id="wsww-spin-position" class="form-select">
                             <option value="left" <?php echo $webequipe_sww_spin_spin_position === 'left' ? 'selected' : ''; ?>>Left Slide
                             </option>
                             <option value="right" <?php echo $webequipe_sww_spin_spin_position === 'right' ? 'selected' : ''; ?>>Right
                                 Slide
                             </option>
                             <option value="inline" <?php echo $webequipe_sww_spin_spin_position === 'inline' ? 'selected' : ''; ?>>Center
                             </option>
                         </select>
                     </div>

                     <fieldset class="mb-3 wsww-form-row">
                        <label class="form-label">Form Field Settings</label>

                        <!-- Email Field (always checked & submitted) -->
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="display-email-field" checked disabled>
                            <input type="hidden" name="display_field_setting[]" value="email_field">
                            <label class="form-check-label" for="display-email-field">
                                Email
                            </label>
                        </div>

                        <!-- Name Field -->
                        <div class="form-check mt-2">
                            <input class="form-check-input" type="checkbox" name="display_field_setting[]"
                                id="displayName-field" value="name_field"
                                <?php echo in_array('name_field', $webequipe_sww_spin_display_fields) ? 'checked' : ''; ?>>
                            <label class="form-check-label" for="displayName-field">
                                Name
                            </label>
                        </div>

                        <!-- Mobile Field -->
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" name="display_field_setting[]"
                                id="displayMobile-field" value="mobile_field"
                                <?php echo in_array('mobile_field', $webequipe_sww_spin_display_fields) ? 'checked' : ''; ?>>
                            <label class="form-check-label" for="displayMobile-field">
                                Mobile
                            </label>
                        </div>
                    </fieldset>
                 </div>
             </div>


         </div>


     </div>



 </div>
