<?php
/**
 * Settings Page Template
 *
 * Displays the plugin settings. Pro sections (General, Privacy & Feedback)
 * are loaded from pro/templates/ when available, otherwise an upsell card is shown.
 *
 * @package Switchboard
 */

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

// Variables expected to be passed:
// $beta_mode - boolean indicating if beta mode is enabled
// $is_licensed - boolean indicating if plugin is licensed
// $all_modules - array of all modules (including beta) for counting

// Get upsell URL for free version fallback
$switchboard_upsell_url = '';
$switchboard_json_path = SWITCHBOARD_PATH . 'pro-modules.json';
if (file_exists($switchboard_json_path)) {
    $switchboard_config = json_decode(file_get_contents($switchboard_json_path), true); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file read
    if (!empty($switchboard_config['upsell_url'])) {
        $switchboard_upsell_url = $switchboard_config['upsell_url'];
    }
}
if (empty($switchboard_upsell_url)) {
    $switchboard_upsell_url = 'https://wpswitchboard.com/pricing';
}

$switchboard_pro_settings_path = SWITCHBOARD_PATH . 'pro/templates/settings-pro-sections.php';
?>

<div class="switchboard-settings-page">
    <div class="sb-settings-grid">
        <!-- Left Column -->
        <div class="sb-settings-column">
            <?php if (file_exists($switchboard_pro_settings_path)):
                include $switchboard_pro_settings_path;
            else: ?>
            <!-- Upgrade to Pro Card (Free only) -->
            <div class="sb-module-card sb-upsell-card">
                <div class="sb-module-card-header">
                    <div class="sb-module-card-header-left">
                        <h3 class="sb-module-card-title">Upgrade to Pro</h3>
                        <p class="sb-module-card-desc">Unlock 50+ premium modules and features</p>
                    </div>
                    <span class="module-badge pro-badge-locked">PRO</span>
                </div>
                <div class="sb-module-card-body">
                    <div class="sb-upsell-features">
                        <div class="sb-upsell-feature">
                            <span class="sb-upsell-check">&#10003;</span>
                            <span>50+ premium modules across all categories</span>
                        </div>
                        <div class="sb-upsell-feature">
                            <span class="sb-upsell-check">&#10003;</span>
                            <span>Configuration presets &amp; cross-site teleport</span>
                        </div>
                        <div class="sb-upsell-feature">
                            <span class="sb-upsell-check">&#10003;</span>
                            <span>Beta mode with early access to new modules</span>
                        </div>
                        <div class="sb-upsell-feature">
                            <span class="sb-upsell-check">&#10003;</span>
                            <span>Priority support &amp; automatic updates</span>
                        </div>
                    </div>
                </div>
                <div class="sb-module-card-footer">
                    <a href="<?php echo esc_url($switchboard_upsell_url); ?>" target="_blank" rel="noopener noreferrer" class="sb-module-button sb-module-button-primary sb-upsell-btn">
                        Upgrade to Pro
                    </a>
                </div>
            </div>
            <?php endif; ?>
        </div>

        <!-- Right Column -->
        <div class="sb-settings-column">
            <!-- Advanced 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">Advanced</h3>
                        <p class="sb-module-card-desc">Cache and data management</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">Clear Cache</span>
                                <span class="sb-settings-item-desc">Refresh module list and clear temporary data</span>
                                <span class="sb-settings-item-help">Use this if modules aren't appearing correctly or after updating.</span>
                            </div>
                            <button type="button" class="sb-module-button sb-module-button-secondary sb-module-button-sm" id="clear-module-cache-page">
                                Clear
                            </button>
                        </div>
                        <div class="sb-settings-item">
                            <div class="sb-settings-item-info">
                                <span class="sb-settings-item-title">Clear Inactive Data</span>
                                <span class="sb-settings-item-desc">Remove data from disabled modules only</span>
                                <span class="sb-settings-item-help">Safely removes settings for modules you've disabled. Active modules are untouched.</span>
                            </div>
                            <button type="button" class="sb-module-button sb-module-button-warning sb-module-button-sm" id="clear-inactive-data-page">
                                Clear
                            </button>
                        </div>
                        <div class="sb-settings-item sb-settings-item-danger">
                            <div class="sb-settings-item-info">
                                <span class="sb-settings-item-title">Clear All Data</span>
                                <span class="sb-settings-item-desc">Delete ALL plugin data permanently</span>
                                <span class="sb-settings-item-help">This cannot be undone. All module settings and configurations will be deleted.</span>
                            </div>
                            <button type="button" class="sb-module-button sb-module-button-danger sb-module-button-sm" id="clear-all-data-page">
                                Delete
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
