<?php
/**
 * Pro Settings Sections (General + Privacy & Feedback)
 *
 * Included from settings-page.php when pro/templates/ exists.
 *
 * @package Switchboard
 */

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

// Variables expected from parent template:
// $beta_mode, $is_licensed, $all_modules

// Get telemetry settings
$telemetry_opted_out = get_option('switchboard_opt_out_telemetry', false);
$feedback_disabled = get_option('switchboard_disable_feedback', true);

// Get beta modules count
$beta_modules_list = [];
if (isset($all_modules) && is_array($all_modules)) {
    foreach ($all_modules as $module) {
        if (isset($module['beta']) && $module['beta']) {
            $beta_modules_list[] = $module['name'];
        }
    }
}
$beta_count = count($beta_modules_list);
?>

<!-- General Settings Section -->
<div class="sb-module-card">
    <div class="sb-module-card-header">
        <div class="sb-module-card-header-left">
            <h3 class="sb-module-card-title">General</h3>
            <p class="sb-module-card-desc">Configure core plugin behavior</p>
        </div>
    </div>
    <div class="sb-module-card-body">
        <div class="sb-settings-list">
            <div class="sb-settings-item">
                <div class="sb-settings-item-info">
                    <span class="sb-settings-item-title">Beta Mode</span>
                    <span class="sb-settings-item-desc">Show experimental modules still in development</span>
                    <span class="sb-settings-item-help"><?php echo $beta_count; ?> beta modules available. These may have bugs or incomplete features.</span>
                    <?php if ($beta_mode && !empty($beta_modules_list)): ?>
                        <span class="sb-settings-item-meta"><?php echo implode(', ', array_slice($beta_modules_list, 0, 5)); ?><?php echo $beta_count > 5 ? ' +' . ($beta_count - 5) . ' more' : ''; ?></span>
                    <?php endif; ?>
                </div>
                <label class="sb-module-toggle">
                    <input type="checkbox" id="beta-mode-toggle-page" <?php echo $beta_mode ? 'checked' : ''; ?>>
                    <span class="sb-module-toggle-slider"></span>
                </label>
            </div>
            <div class="sb-settings-item">
                <div class="sb-settings-item-info">
                    <span class="sb-settings-item-title">License</span>
                    <span class="sb-settings-item-desc"><?php echo $is_licensed ? 'All premium modules unlocked' : 'Activate to unlock premium modules'; ?></span>
                    <span class="sb-settings-item-help">Your license key unlocks all premium features and enables automatic updates.</span>
                </div>
                <div class="sb-settings-item-actions">
                    <span class="sb-settings-badge <?php echo $is_licensed ? 'active' : ''; ?>">
                        <?php echo $is_licensed ? 'Active' : 'Inactive'; ?>
                    </span>
                    <button type="button" class="sb-settings-link" onclick="openLicenseModal();">Manage</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Privacy & Feedback Section -->
<div class="sb-module-card">
    <div class="sb-module-card-header">
        <div class="sb-module-card-header-left">
            <h3 class="sb-module-card-title">Privacy & Feedback</h3>
            <p class="sb-module-card-desc">Control what data is shared</p>
        </div>
    </div>
    <div class="sb-module-card-body">
        <div class="sb-settings-list">
            <div class="sb-settings-item">
                <div class="sb-settings-item-info">
                    <span class="sb-settings-item-title">Usage Analytics</span>
                    <span class="sb-settings-item-desc">Share anonymous data like active modules and plugin version</span>
                    <span class="sb-settings-item-help">Helps us understand how the plugin is used. No personal data is ever collected.</span>
                </div>
                <label class="sb-module-toggle">
                    <input type="checkbox" id="telemetry-toggle-page" <?php echo !$telemetry_opted_out ? 'checked' : ''; ?>>
                    <span class="sb-module-toggle-slider"></span>
                </label>
            </div>
            <div class="sb-settings-item">
                <div class="sb-settings-item-info">
                    <span class="sb-settings-item-title">Feedback Popups</span>
                    <span class="sb-settings-item-desc">Show popup when disabling modules asking why</span>
                    <span class="sb-settings-item-help">Quick feedback helps us improve modules and fix issues faster.</span>
                </div>
                <label class="sb-module-toggle">
                    <input type="checkbox" id="feedback-toggle-page" <?php echo !$feedback_disabled ? 'checked' : ''; ?>>
                    <span class="sb-module-toggle-slider"></span>
                </label>
            </div>
        </div>
    </div>
</div>
