<?php
/**
 * VMPFence Scan Options and Scheduling View
 *
 * @package VMPFence
 * @since 1.0.0
 * @since 2.0.0 Updated to reflect VMP WordPress Security branding.
 * @since 2.1.0 Added dynamic scan status and scheduling options.
 * @since 2.2.2 Updated to reflect VMP Security branding.
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Load current scan type and get corresponding configuration
require_once VMPFENCE_PLUGIN_DIR . 'lib/class-vmpfence-scan-config.php';
$current_scan_type = VMPFence_Config::get('scanType', 'standard');
$current_scan_options = VMPFence_Scan_Config::getScanOptions($current_scan_type);

// Load current performance options for display
$current_options = array(
    'lowResourceScansEnabled' => VMPFence_Config::get('lowResourceScansEnabled', false),
    'scan_maxIssues' => VMPFence_Config::get('scan_maxIssues', 1000),
    'scan_maxDuration' => VMPFence_Config::get('scan_maxDuration', ''),
    'maxMem' => VMPFence_Config::get('maxMem', 256),
    'scan_maxExecTime' => VMPFence_Config::get('scan_maxExecTime', 0),
    'scan_max_resume_attempts' => VMPFence_Config::get('scan_max_resume_attempts', 2)
);

// Load current scheduling options for debugging
// $current_scheduling = array(
//     'scheduledScansEnabled' => VMPFence_Config::get('scheduledScansEnabled', false),
//     'schedMode' => VMPFence_Config::get('schedMode', 'auto'),
//     'manualScanType' => VMPFence_Config::get('manualScanType', 'once_daily'),
//     'schedStartHour' => VMPFence_Config::get('schedStartHour', 2),
//     'scheduleTimezone' => VMPFence_Config::get('scheduleTimezone', wp_timezone_string()),
//     'randomOffset' => VMPFence_Config::get('randomOffset', '0')
// );

// Debug: Log what values are loaded from database
// error_log('VMPFence: Page load - scheduling values from DB: ' . print_r($current_scheduling, true));

// Enqueue scan options CSS
wp_enqueue_style('vmpfence-scan-options-css', plugins_url('assets/css/scan-options.css', dirname(__FILE__)), array(), '2.0.1');

// Enqueue toast notification system
wp_enqueue_style('vmpfence-toast-notifications', plugins_url('assets/css/toast-notifications.css', dirname(__FILE__)), array(), '1.0.3');
wp_enqueue_script('vmpfence-toast-notifications', plugins_url('assets/js/toast-notifications.js', dirname(__FILE__)), array('jquery'), '1.0.3', true);

// Enqueue scan options JavaScript files
wp_enqueue_script(
    'vmpfence-scan-options-js',
    plugins_url('assets/js/scan-options.js', dirname(__FILE__)),
    array('jquery'),
    VMPFENCE_VERSION,
    true
);

wp_enqueue_script(
    'vmpfence-scan-options-ui-js',
    plugins_url('assets/js/scan-options-ui.js', dirname(__FILE__)),
    array('jquery', 'vmpfence-scan-options-js'),
    VMPFENCE_VERSION,
    true
);

// Localize scripts with AJAX configuration
$ajax_url = admin_url('admin-ajax.php');

// For scan-options.js (main functionality) - uses vmpfence_scan_options
wp_localize_script(
    'vmpfence-scan-options-js',
    'vmpfence_ajax',
    array(
        'ajax_url' => $ajax_url,
        'nonce' => wp_create_nonce('vmpfence_scan_options')
    )
);

// For scan-options-ui.js (UI functions) - uses vmpfence_scan_options
wp_localize_script(
    'vmpfence-scan-options-ui-js',
    'vmpfence_options_ajax',
    array(
        'ajax_url' => $ajax_url,
        'nonce' => wp_create_nonce('vmpfence_scan_options'),
        'security_nonce' => wp_create_nonce('vmpfence_scan_nonce')  // For security scores only
    )
);
?>

<!-- Top Navigation Bar -->
<div class="vmpfence-options-header vmpfence-sticky-header">
    <div class="vmpfence-options-nav">
        <a href="<?php echo esc_url( admin_url('admin.php?page=vmpfence-scan') ); ?>" class="vmpfence-back-link">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M15 18L9 12L15 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
            </svg>
            Back to Scan
        </a>
    </div>
    <div class="vmpfence-options-actions">
        <button class="vmpfence-btn-restore">RESTORE DEFAULTS</button>
        <button class="vmpfence-btn-cancel">CANCEL CHANGES</button>
        <button class="vmpfence-btn-save">SAVE CHANGES</button>
        
        <!-- Nonce field for AJAX security -->
        <input type="hidden" id="vmpfence_scan_options_nonce" value="<?php echo esc_attr( wp_create_nonce('vmpfence_scan_options') ); ?>">
    </div>
</div>

<!-- Main Options Content -->
<div class="vmpfence-options-content">
    
    <!-- Title Section -->
    <div class="vmpfence-options-title-section">
        <div class="vmpfence-options-title">
            <h1>
                <img src="<?php echo esc_url( VMPFENCE_PLUGIN_URL . 'admin/assets/images/VMP-logo.svg' ); ?>" alt="VMP Fence" style="width: 32px; height: 32px; vertical-align: middle; margin-right: 10px;"> 
                Scan Options and Scheduling
            </h1>
        </div>
        <!-- <div class="vmpfence-options-learn-more">
            <a href="#" class="vmpfence-learn-more-link">Learn more about Scanning ↗</a>
        </div> -->
    </div>
    
    <!-- Three Progress Cards -->
    <div class="vmpfence-options-cards-row">
        <!-- Scan Type Card -->
        <div class="vmpfence-options-card">
            <div class="vmpfence-options-progress" data-status-type="scan_type_page">
                <?php
                // Calculate scan type percentage: 30% premium + 11% reputation + 59% options
                require_once VMPFENCE_PLUGIN_DIR . 'status-modal/models/class-scanner-status.php';
                $scan_status = VMPFence_Scanner_Status::get_scan_type_card_status();
                $scan_percentage = round($scan_status['percentage'] * 100);
                
                // Set color based on percentage
                if ($scan_percentage >= 80) {
                    $scan_color = '#28a745'; // Green
                } elseif ($scan_percentage >= 60) {
                    $scan_color = '#17a2b8'; // Blue
                } elseif ($scan_percentage >= 40) {
                    $scan_color = '#ffc107'; // Yellow
                } else {
                    $scan_color = '#dc3545'; // Red
                }
                
                // Get scan type for title
                $scan_type = (string) VMPFence_Config::get('scanType');
                $scan_type = ucwords(str_replace('_', ' ', strtolower($scan_type)));
                ?>
                <svg class="vmpfence-circle-chart" viewBox="0 0 33.83098862 33.83098862" width="100" height="100">
                    <circle class="vmpfence-circle-bg" stroke="#e6e6e6" stroke-width="2" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <circle class="vmpfence-circle-progress-bar" id="scan-types-progress" stroke="<?php echo esc_attr($scan_color); ?>" stroke-width="2" stroke-dasharray="<?php echo esc_attr($scan_percentage); ?>,100" stroke-linecap="round" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <text x="16.91549431" y="20" text-anchor="middle"  transform="rotate(-90 16.91549431 16.91549431)" font-size="6" font-weight="bold" class="vmpfence-circle-text" id="scan-types-text"><?php echo esc_html($scan_percentage); ?>%</text>
                </svg>
            </div>
            <div class="vmpfence-options-card-info">
                <h3 id="scan-types-title">Scan Type: <?php echo esc_html($scan_type); ?></h3>
                <p id="scan-types-description"><?php echo esc_html($scan_type); ?> detection capability</p>
            </div>
        </div>

        <!-- Malware Signatures Card -->
        <div class="vmpfence-options-card">
            <div class="vmpfence-options-progress" data-status-type="malware_signatures">
                <?php
                // Calculate malware signatures percentage: 70% free + 30% premium
                $license_type = VMPFence_License::get_license_type();
                $is_premium = ($license_type === VMPFence_Constants::LICENSE_PREMIUM);
                $malware_percentage = 70; // Base 70% for free users
                if ($is_premium) {
                    $malware_percentage = 100; // 70% + 30% = 100% for premium
                }
                
                // Set color based on percentage
                if ($malware_percentage >= 80) {
                    $malware_color = '#28a745'; // Green
                } elseif ($malware_percentage >= 60) {
                    $malware_color = '#17a2b8'; // Blue
                } elseif ($malware_percentage >= 40) {
                    $malware_color = '#ffc107'; // Yellow
                } else {
                    $malware_color = '#dc3545'; // Red
                }
                ?>
                <svg class="vmpfence-circle-chart" viewBox="0 0 33.83098862 33.83098862" width="100" height="100">
                    <circle class="vmpfence-circle-bg" stroke="#e6e6e6" stroke-width="2" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <circle id="malware-signatures-progress" class="vmpfence-circle-progress-bar" stroke="<?php echo esc_attr($malware_color); ?>" stroke-width="2" stroke-dasharray="<?php echo esc_attr($malware_percentage); ?>,100" stroke-linecap="round" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <text id="malware-signatures-text" x="16.91549431" y="20" text-anchor="middle"  transform="rotate(-90 16.91549431 16.91549431)" font-size="6" font-weight="bold" class="vmpfence-circle-text"><?php echo esc_html($malware_percentage); ?>%</text>
                </svg>
            </div>
            <div class="vmpfence-options-card-info">
                <h3 id="malware-signatures-title">Malware Signatures</h3>
                <p id="malware-signatures-description"><?php echo $is_premium ? 'Premium malware detection signatures enabled' : 'Essential malware detection signatures included'; ?></p>
            </div>
        </div>

        <!-- Reputation Checks Card -->
        <div class="vmpfence-options-card">
            <div class="vmpfence-options-progress" data-status-type="reputation_checks">
                <?php
                // Calculate reputation checks percentage: Spamvertizing (33%) + Spam IP (33%) + GSB Blocklist (33%)
                $spamvertize = (bool) VMPFence_Config::get('spamvertizeCheck', 0);
                $spam_ip = (bool) VMPFence_Config::get('checkSpamIP', 0);
                $gsb = (bool) VMPFence_Config::get('scansEnabled_checkGSB', 0);
                
                $reputation_percentage = 0;
                if ($spamvertize) $reputation_percentage += 33;
                if ($spam_ip) $reputation_percentage += 33;
                if ($gsb) $reputation_percentage += 33;
                
                // Round 99 to 100 when all three checks are enabled
                if ($reputation_percentage == 99) {
                    $reputation_percentage = 100;
                }
                
                // Set color based on percentage
                if ($reputation_percentage >= 80) {
                    $reputation_color = '#28a745'; // Green
                } elseif ($reputation_percentage >= 60) {
                    $reputation_color = '#17a2b8'; // Blue
                } elseif ($reputation_percentage >= 40) {
                    $reputation_color = '#ffc107'; // Yellow
                } else {
                    $reputation_color = '#dc3545'; // Red
                }
                ?>
                <svg class="vmpfence-circle-chart" viewBox="0 0 33.83098862 33.83098862" width="100" height="100">
                    <circle class="vmpfence-circle-bg" stroke="#e6e6e6" stroke-width="2" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <circle class="vmpfence-circle-progress-bar" stroke="<?php echo esc_attr($reputation_color); ?>" stroke-width="2" stroke-dasharray="<?php echo esc_attr($reputation_percentage); ?>,100" stroke-linecap="round" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431"></circle>
                    <text x="16.91549431" y="20" text-anchor="middle"  transform="rotate(-90 16.91549431 16.91549431)" font-size="6" font-weight="bold" class="vmpfence-circle-text"><?php echo esc_html($reputation_percentage); ?>%</text>
                </svg>
            </div>
            <div class="vmpfence-options-card-info">
                <h3>Reputation Checks</h3>
                <p>Check spam & spamvertising blocklists</p>
            </div>
        </div>
    </div>

    <!-- Collapsible Sections -->
    <div class="vmpfence-options-sections">
        
        <!-- Scan Scheduling Section -->
        <div class="vmpfence-options-section">
            <div class="vmpfence-options-section-header" onclick="toggleSection('scheduling')">
                <h3>Scan Scheduling</h3>
                <span class="vmpfence-arrow" id="scheduling-arrow">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M9 18L15 12L9 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                </span>
            </div>
            <div class="vmpfence-options-section-content" id="scheduling-content">
                
                <!-- Schedule VMPFence Scans Toggle -->
                <div class="vmpfence-schedule-toggle-section">
                    <div class="vmpfence-schedule-toggle-header">
                        <label class="vmpfence-schedule-label">Schedule VMP Security Scans</label>
                        <div class="vmpfence-toggle-buttons">
                            <button class="vmpfence-toggle-btn vmpfence-toggle-disabled" data-value="disabled">DISABLED</button>
                            <button class="vmpfence-toggle-btn vmpfence-toggle-enabled active" data-value="enabled">ENABLED</button>
                        </div>
                    </div>
                </div>

                <!-- Horizontal divider -->
                <hr class="vmpfence-section-divider">

                <!-- Scheduling Mode Options -->
                <div class="vmpfence-schedule-options" style="margin-top: 20px;">
                    
                    <!-- Automatic Scheduling Option -->
                    <div class="vmpfence-schedule-option">
                        <div class="vmpfence-schedule-radio-group">
                            <input type="radio" name="schedule_mode" value="auto" id="schedule-auto" <?php 
                                $current_schedule_mode = VMPFence_Config::get('schedMode', 'auto');
                                // error_log('VMPFence: schedMode value: ' . var_export($current_schedule_mode, true));
                                checked($current_schedule_mode, 'auto'); 
                            ?>>
                            <label for="schedule-auto" class="vmpfence-schedule-radio-label">
                                <span class="vmpfence-radio-text">Let VMP Security choose when to scan my site <span class="vmpfence-recommended">(recommended)</span></span>
                            </label>
                        </div>
                    </div>

                    <!-- Manual Scheduling Option -->
                    <div class="vmpfence-schedule-option">
                        <div class="vmpfence-schedule-radio-group">
                            <input type="radio" name="schedule_mode" value="manual" id="schedule-manual" <?php checked($current_schedule_mode, 'manual'); ?>>
                            <label for="schedule-manual" class="vmpfence-schedule-radio-label">
                                <span class="vmpfence-radio-text">Manually schedule scans</span>
                            </label>
                        </div>
                    </div>

                </div>

                <!-- Manual Scheduling Configuration -->
                <div id="manual-schedule-config" class="vmpfence-manual-schedule-config" style="display: none; margin-top: 30px;">
                    
                    <!-- Pattern Selection -->
                    <div class="vmpfence-option-item">
                        <label for="manual-schedule-pattern" class="vmpfence-option-label">Schedule Pattern</label>
                        <div class="vmpfence-form-control-wrapper">
                            <select id="manual-schedule-pattern" name="manual_schedule_pattern" class="vmpfence-select">
                                <?php 
                                $current_pattern = VMPFence_Config::get('manualScanType', 'once_daily');
                                // error_log('VMPFence: manualScanType value: ' . var_export($current_pattern, true));
                                ?>
                                <option value="once_daily" <?php selected($current_pattern, 'once_daily'); ?>>Once Daily</option>
                                <option value="twice_daily" <?php selected($current_pattern, 'twice_daily'); ?>>Twice Daily</option>
                                <option value="every_other_day" <?php selected($current_pattern, 'every_other_day'); ?>>Every Other Day</option>
                                <option value="weekdays" <?php selected($current_pattern, 'weekdays'); ?>>Weekdays Only</option>
                                <option value="weekends" <?php selected($current_pattern, 'weekends'); ?>>Weekends Only</option>
                                <option value="odd_days_weekends" <?php selected($current_pattern, 'odd_days_weekends'); ?>>Mon/Wed/Fri + Weekends</option>
                                <option value="custom" <?php selected($current_pattern, 'custom'); ?>>Custom Schedule</option>
                            </select>
                            <p class="vmpfence-option-description">Choose how frequently you want scans to run.</p>
                        </div>
                    </div>

                    <!-- Start Time Selection -->
                    <div class="vmpfence-option-item" id="start-time-config">
                        <label for="schedule-start-hour" class="vmpfence-option-label">Preferred Start Time</label>
                        <div class="vmpfence-form-control-wrapper">
                            <select id="schedule-start-hour" name="schedule_start_hour" class="vmpfence-select">
                                <?php for ($hour = 0; $hour < 24; $hour++): ?>
                                    <option value="<?php echo esc_attr($hour); ?>" <?php selected($hour, VMPFence_Config::get('schedStartHour', 2)); ?>>
                                        <?php echo esc_html( sprintf('%02d:00 (%s)', $hour, $hour < 12 ? 'AM' : 'PM') ); ?>
                                    </option>
                                <?php endfor; ?>
                            </select>
                            <p class="vmpfence-option-description">Choose the hour when you prefer scans to start.</p>
                        </div>
                    </div>

                    <!-- Timezone Selection -->
                    <div class="vmpfence-option-item">
                        <label for="schedule-timezone" class="vmpfence-option-label">Timezone</label>
                        <div class="vmpfence-form-control-wrapper">
                            <select id="schedule-timezone" name="schedule_timezone" class="vmpfence-select">
                                <?php
                                $current_timezone = VMPFence_Config::get('scheduleTimezone', wp_timezone_string());
                                $timezone_identifiers = timezone_identifiers_list();
                                foreach ($timezone_identifiers as $timezone) {
                                    echo '<option value="' . esc_attr($timezone) . '"' . selected($timezone, $current_timezone, false) . '>' . esc_html($timezone) . '</option>';
                                }
                                ?>
                            </select>
                            <p class="vmpfence-option-description">All scan times will use this timezone.</p>
                        </div>
                    </div>

                    <!-- Random Offset Option -->
                    <div class="vmpfence-option-item">
                        <label class="vmpfence-option-label">Random Offset</label>
                        <div class="vmpfence-form-control-wrapper">
                            <div class="vmpfence-checkbox-group">
                                <input type="checkbox" id="random-offset" name="random_offset" value="1" <?php 
                                $random_offset_value = VMPFence_Config::get('randomOffset', '0');
                                // Debug the actual value
                                // error_log('VMPFence: randomOffset checkbox value: ' . var_export($random_offset_value, true) . ' (type: ' . gettype($random_offset_value) . ')');
                                // Now we expect '1' for checked, '0' for unchecked
                                echo checked($random_offset_value, '1', false); 
                                ?>>
                                <label for="random-offset" class="vmpfence-checkbox-label">
                                    Add random offset (0-60 minutes)
                                </label>
                            </div>
                            <p class="vmpfence-option-description">
                                Adds a random delay (0-60 minutes) to prevent all sites from scanning at the same time.
                            </p>
                        </div>
                    </div>

                    <!-- Custom Schedule Grid -->
                    <div id="custom-schedule-grid" class="vmpfence-custom-schedule" style="display: none;">
                        <h4>Custom Schedule Grid</h4>
                        <p class="vmpfence-option-description">Select the hours when you want scans to run. Times are in your selected timezone.</p>
                        
                        <div class="vmpfence-schedule-grid">
                            <div class="vmpfence-schedule-header">
                                <div class="vmpfence-schedule-time-label">Time</div>
                                <div class="vmpfence-schedule-day-label">Sun</div>
                                <div class="vmpfence-schedule-day-label">Mon</div>
                                <div class="vmpfence-schedule-day-label">Tue</div>
                                <div class="vmpfence-schedule-day-label">Wed</div>
                                <div class="vmpfence-schedule-day-label">Thu</div>
                                <div class="vmpfence-schedule-day-label">Fri</div>
                                <div class="vmpfence-schedule-day-label">Sat</div>
                            </div>
                            
                            <?php for ($hour = 0; $hour < 24; $hour++): ?>
                            <div class="vmpfence-schedule-row">
                                <div class="vmpfence-schedule-time"><?php echo esc_html( sprintf('%02d:00', $hour) ); ?></div>
                                <?php for ($day = 0; $day < 7; $day++): ?>
                                <div class="vmpfence-schedule-cell">
                                    <input type="checkbox" 
                                           name="custom_schedule[<?php echo esc_attr($day); ?>][<?php echo esc_attr($hour); ?>]" 
                                           id="schedule-<?php echo esc_attr($day); ?>-<?php echo esc_attr($hour); ?>"
                                           class="vmpfence-schedule-checkbox">
                                    <label for="schedule-<?php echo esc_attr($day); ?>-<?php echo esc_attr($hour); ?>" class="vmpfence-schedule-cell-label"></label>
                                </div>
                                <?php endfor; ?>
                            </div>
                            <?php endfor; ?>
                        </div>

                        <div class="vmpfence-schedule-controls">
                            <button type="button" class="vmpfence-btn-secondary" id="select-all-hours">Select All</button>
                            <button type="button" class="vmpfence-btn-secondary" id="clear-all-hours">Clear All</button>
                            <button type="button" class="vmpfence-btn-secondary" id="select-business-hours">Business Hours</button>
                            <button type="button" class="vmpfence-btn-secondary" id="select-night-hours">Night Hours</button>
                        </div>
                    </div>

                </div>

                <!-- Schedule Preview Section -->
                <div id="schedule-preview" class="vmpfence-schedule-preview" style="margin-top: 30px;">
                    <h4>Schedule Preview</h4>
                    <div id="schedule-preview-content" class="vmpfence-schedule-preview-content">
                        <p>Enable scheduling to see upcoming scan times.</p>
                    </div>
                    <button type="button" id="refresh-schedule-preview" class="vmpfence-btn-secondary" style="margin-top: 15px;">
                        Refresh Preview
                    </button>
                </div>

                <!-- Schedule Status -->
                <div id="schedule-status" class="vmpfence-schedule-status" style="margin-top: 20px;">
                    <div class="vmpfence-status-item">
                        <strong>Next Scan:</strong> <span id="next-scan-time">Not scheduled</span>
                    </div>
                    <div class="vmpfence-status-item">
                        <strong>Schedule Mode:</strong> <span id="current-schedule-mode">Automatic</span>
                    </div>
                    <div class="vmpfence-status-item">
                        <strong>Last Updated:</strong> <span id="last-schedule-update">Never</span>
                    </div>
                </div>
                
            </div>
        </div>

        <!-- Basic Scan Type Options Section -->
        <div class="vmpfence-options-section vmpfence-section-expanded vmpfence-section-fixed">
            <div class="vmpfence-options-section-header-fixed">
                <h3>Basic Scan Type Options</h3>
            </div>
            <div class="vmpfence-options-section-content">
                
                <!-- Scan Type Cards Grid -->
                <div class="vmpfence-scan-types-grid">
                    
                    <!-- Limited Scan -->
                    <div class="vmpfence-scan-type-card <?php echo ($current_scan_type === 'limited') ? 'vmpfence-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-scan-type-header">
                            <input type="checkbox" name="scan_type[]" value="limited" id="scan-limited" <?php echo ($current_scan_type === 'limited') ? 'checked' : ''; ?>>
                            <label for="scan-limited" class="vmpfence-scan-type-title">Limited Scan</label>
                        </div>
                        <div class="vmpfence-scan-type-body">
                            <p class="vmpfence-scan-type-description">For entry-level hosting plans. Provides limited detection capability with very low resource utilization.</p>
                        </div>
                    </div>

                    <!-- Standard Scan -->
                    <div class="vmpfence-scan-type-card <?php echo ($current_scan_type === 'standard') ? 'vmpfence-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-scan-type-header">
                            <input type="checkbox" name="scan_type[]" value="standard" id="scan-standard" <?php echo ($current_scan_type === 'standard') ? 'checked' : ''; ?>>
                            <label for="scan-standard" class="vmpfence-scan-type-title">Standard Scan</label>
                        </div>
                        <div class="vmpfence-scan-type-body">
                            <p class="vmpfence-scan-type-description">Our recommendation for all websites. Provides the best detection capability in the industry.</p>
                        </div>
                    </div>

                    <!-- High Sensitivity -->
                    <div class="vmpfence-scan-type-card <?php echo ($current_scan_type === 'high_sensitivity') ? 'vmpfence-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-scan-type-header">
                            <input type="checkbox" name="scan_type[]" value="high_sensitivity" id="scan-high" <?php echo ($current_scan_type === 'high_sensitivity') ? 'checked' : ''; ?>>
                            <label for="scan-high" class="vmpfence-scan-type-title">High Sensitivity</label>
                        </div>
                        <div class="vmpfence-scan-type-body">
                            <p class="vmpfence-scan-type-description">For site owners who think they may have been hacked. More thorough but may produce false positives.</p>
                        </div>
                    </div>

                    <!-- Custom Scan (Hidden checkbox, auto-selected when options change) -->
                    <div class="vmpfence-scan-type-card vmpfence-custom-scan-card <?php echo ($current_scan_type === 'custom') ? 'vmpfence-scan-type-selected' : ''; ?>">
                        <div class="vmpfence-scan-type-header">
                            <input type="checkbox" name="scan_type[]" value="custom" id="scan-custom" style="display: none;" <?php echo ($current_scan_type === 'custom') ? 'checked' : ''; ?>>
                            <label for="scan-custom" class="vmpfence-scan-type-title">Custom Scan</label>
                        </div>
                        <div class="vmpfence-scan-type-body">
                            <p class="vmpfence-scan-type-description">Selected automatically when General Options have been customized for this website.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- General Options Section -->
        <div class="vmpfence-options-section">
            <div class="vmpfence-options-section-header" onclick="toggleSection('general')">
                <h3>General Options</h3>
                <span class="vmpfence-arrow" id="general-arrow">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M9 18L15 12L9 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                </span>
            </div>
            <div class="vmpfence-options-section-content" id="general-content">
                
                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_checkGSB" value="1" <?php echo !empty($current_scan_options['scansEnabled_checkGSB']) ? 'checked' : ''; ?> onchange="selectCustomScan(); updateReputationPercentageDynamic();">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Check if this website is on a domain blocklist</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="spamvertizeCheck" value="1" <?php echo !empty($current_scan_options['spamvertizeCheck']) ? 'checked' : ''; ?> onchange="selectCustomScan(); updateReputationPercentageDynamic();">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Check if this website is being "Spamvertised"</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="checkSpamIP" value="1" <?php echo !empty($current_scan_options['checkSpamIP']) ? 'checked' : ''; ?> onchange="selectCustomScan(); updateReputationPercentageDynamic();">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Check if this website IP is generating spam</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_checkHowGetIPs" value="1" <?php echo !empty($current_scan_options['scansEnabled_checkHowGetIPs']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for misconfigured How does VMP Security get IPs</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_checkReadableConfig" value="1" <?php echo !empty($current_scan_options['scansEnabled_checkReadableConfig']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for publicly accessible configuration, backup, or log files</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_suspectedFiles" value="1" <?php echo !empty($current_scan_options['scansEnabled_suspectedFiles']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for publicly accessible quarantined files</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_core" value="1" <?php echo !empty($current_scan_options['scansEnabled_core']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan core files against repository versions for changes</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_themes" value="1" <?php echo !empty($current_scan_options['scansEnabled_themes']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan theme files against repository versions for changes</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_plugins" value="1" <?php echo !empty($current_scan_options['scansEnabled_plugins']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan plugin files against repository versions for changes</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_coreUnknown" value="1" <?php echo !empty($current_scan_options['scansEnabled_coreUnknown']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan wp-admin and wp-includes for files not bundled with WordPress</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_malware" value="1" <?php echo !empty($current_scan_options['scansEnabled_malware']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for signatures of known malicious files</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_fileContents" value="1" <?php echo !empty($current_scan_options['scansEnabled_fileContents']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan file contents for backdoors, trojans and suspicious code</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_fileContentsGSB" value="1" <?php echo !empty($current_scan_options['scansEnabled_fileContentsGSB']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan file contents for malicious URLs</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_posts" value="1" <?php echo !empty($current_scan_options['scansEnabled_posts']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan posts for known dangerous URLs and suspicious content</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_comments" value="1" <?php echo !empty($current_scan_options['scansEnabled_comments']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan comments for known dangerous URLs and suspicious content</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_suspiciousOptions" value="1" <?php echo !empty($current_scan_options['scansEnabled_suspiciousOptions']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan WordPress core, plugin, and theme options for known dangerous URLs and suspicious content</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_oldVersions" value="1" <?php echo !empty($current_scan_options['scansEnabled_oldVersions']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for out of date, abandoned, and vulnerable plugins, themes, and WordPress versions</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_suspiciousAdminUsers" value="1" <?php echo !empty($current_scan_options['scansEnabled_suspiciousAdminUsers']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan for suspicious admin users created outside of WordPress</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_passwds" value="1" <?php echo !empty($current_scan_options['scansEnabled_passwds']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Check the strength of passwords</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_diskSpace" value="1" <?php echo !empty($current_scan_options['scansEnabled_diskSpace']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Monitor disk space</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_wafStatus" value="1" <?php echo !empty($current_scan_options['scansEnabled_wafStatus']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Monitor Web Application Firewall status</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="other_scanOutside" value="1" <?php echo !empty($current_scan_options['other_scanOutside']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan files outside your WordPress installation</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scansEnabled_scanImages" value="1" <?php echo !empty($current_scan_options['scansEnabled_scanImages']) ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Scan images, binary, and other files as if they were executable</span>
                    </label>
                </div>

            </div>
        </div>

        <!-- Performance Options Section -->
        <div class="vmpfence-options-section">
            <div class="vmpfence-options-section-header" onclick="toggleSection('performance')">
                <h3>Performance Options</h3>
                <span class="vmpfence-arrow" id="performance-arrow">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M9 18L15 12L9 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                </span>
            </div>
            <div class="vmpfence-options-section-content" id="performance-content">
                
                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="lowResourceScansEnabled" value="1" <?php echo $current_options['lowResourceScansEnabled'] ? 'checked' : ''; ?> onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Use low resource scanning (reduces server load by lengthening the scan duration)</span>
                    </label>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-input-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Limit the number of issues sent in the scan results email</span>
                    </label>
                    <input type="number" name="scan_maxIssues" value="<?php echo esc_attr($current_options['scan_maxIssues']); ?>" min="0" class="vmpfence-number-input" onchange="selectCustomScan()">
                    <p class="vmpfence-option-description">0 or empty means unlimited issues will be sent</p>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-input-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Time limit that a scan can run in seconds</span>
                    </label>
                    <input type="number" name="scan_maxDuration" value="<?php echo esc_attr($current_options['scan_maxDuration']); ?>" min="0" class="vmpfence-number-input" onchange="selectCustomScan()">
                    <p class="vmpfence-option-description">0 or empty means the default of 3 hours will be used</p>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-input-label">
                        <span class="vmpfence-option-text"  style="padding-left: 30px;">How much memory should VMP Security request when scanning</span>
                    </label>
                    <input type="number" name="maxMem" value="<?php echo esc_attr($current_options['maxMem']); ?>" min="64" class="vmpfence-number-input" onchange="selectCustomScan()">
                    <p class="vmpfence-option-description">Memory size in megabytes</p>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-input-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Maximum execution time for each scan stage</span>
                    </label>
                    <input type="number" name="scan_maxExecTime" value="<?php echo esc_attr($current_options['scan_maxExecTime']); ?>" min="0" class="vmpfence-number-input" onchange="selectCustomScan()">
                    <p class="vmpfence-option-description">0 for default. Must be 8 or greater and 10-20 or higher is recommended for most servers</p>
                </div>

            </div>
        </div>

        <!-- Advanced Scan Options Section -->
        <div class="vmpfence-options-section">
            <div class="vmpfence-options-section-header" onclick="toggleSection('advanced')">
                <h3>Advanced Scan Options</h3>
                <span class="vmpfence-arrow" id="advanced-arrow">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M9 18L15 12L9 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                </span>
            </div>
            <div class="vmpfence-options-section-content" id="advanced-content">
                
                <div class="vmpfence-option-item">
                    <label class="vmpfence-textarea-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Exclude files from scan that match these wildcard patterns (one per line)</span>
                    </label>
                    <textarea name="scan_exclude" rows="4" class="vmpfence-textarea" onchange="selectCustomScan()"></textarea>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-textarea-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Additional scan signatures (one per line)</span>
                    </label>
                    <textarea name="scan_include_extra" rows="4" class="vmpfence-textarea" onchange="selectCustomScan()"></textarea>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-checkbox-container">
                        <input type="checkbox" name="scan_force_ipv4_start" value="1" onchange="selectCustomScan()">
                        <span class="vmpfence-checkmark"></span>
                        <span class="vmpfence-option-text">Use only IPv4 to start scans</span>
                    </label>
                    <p class="vmpfence-option-description">This option requires cURL. (This may have no effect on some old PHP or cURL versions.)</p>
                </div>

                <div class="vmpfence-option-item">
                    <label class="vmpfence-select-label">
                        <span class="vmpfence-option-text" style="padding-left: 30px;">Maximum number of attempts to resume each scan stage</span>
                    </label>
                    <select name="scan_max_resume_attempts" class="vmpfence-select" onchange="selectCustomScan()">
                        <option value="1"<?php echo ($current_options['scan_max_resume_attempts'] == 1) ? ' selected' : ''; ?>>1</option>
                        <option value="2"<?php echo ($current_options['scan_max_resume_attempts'] == 2) ? ' selected' : ''; ?>>2</option>
                        <option value="3"<?php echo ($current_options['scan_max_resume_attempts'] == 3) ? ' selected' : ''; ?>>3</option>
                        <option value="4"<?php echo ($current_options['scan_max_resume_attempts'] == 4) ? ' selected' : ''; ?>>4</option>
                        <option value="5"<?php echo ($current_options['scan_max_resume_attempts'] == 5) ? ' selected' : ''; ?>>5</option>
                        <option value="10"<?php echo ($current_options['scan_max_resume_attempts'] == 10) ? ' selected' : ''; ?>>10</option>
                        <option value="20"<?php echo ($current_options['scan_max_resume_attempts'] == 20) ? ' selected' : ''; ?>>20</option>
                    </select>
                </div>

            </div>
        </div>

    </div>
</div>

