<?php
/**
 * Super Agency Theme Settings Page
 * 
 * @package Super Agency
 * @since 1.0.5
 */

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

class Super_Agency_Settings {
    
    /**
     * Constructor
     */
    public function __construct() {
        add_action('admin_menu', array($this, 'add_admin_menu'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
        add_action('wp_ajax_super_agency_get_plugins', array($this, 'get_predefined_plugins'));
        add_action('wp_ajax_super_agency_install_plugin', array($this, 'install_plugin'));
        add_action('current_screen', array($this, 'suppress_admin_notices'));
        add_action('admin_post_super_agency_save_settings', array($this, 'save_settings'));
    }

    /**
     * Save theme settings form submission.
     */
    public function save_settings() {
        check_admin_referer('super_agency_save_settings');

        if (!current_user_can('manage_options')) {
            wp_die(__('You do not have permission to change these settings.', 'super-agency'));
        }

        $sticky_header = isset($_POST['sticky_header']) ? 'yes' : 'no';
        update_option('super_agency_sticky_header', $sticky_header);

        wp_redirect(add_query_arg(array(
            'page'  => 'super-agency-settings',
            'tab'   => 'theme-settings',
            'saved' => '1',
        ), admin_url('themes.php')));
        exit;
    }

    /**
     * Remove third-party admin notices from our settings page.
     */
    public function suppress_admin_notices() {
        $screen = get_current_screen();
        if ( $screen && $screen->id === 'appearance_page_super-agency-settings' ) {
            remove_all_actions('admin_notices');
            remove_all_actions('all_admin_notices');
        }
    }
    
    /**
     * Add admin menu page
     */
    public function add_admin_menu() {
        add_theme_page(
            __('Super Agency Settings', 'super-agency'),
            __('Super Agency', 'super-agency'),
            'manage_options',
            'super-agency-settings',
            array($this, 'settings_page')
        );
    }
    
    /**
     * Enqueue admin scripts and styles
     */
    public function enqueue_admin_scripts($hook) {
        if ($hook !== 'appearance_page_super-agency-settings') {
            return;
        }
        
        wp_enqueue_style(
            'super-agency-admin',
            get_template_directory_uri() . '/assets/css/admin-style.css',
            array(),
            SUPER_AGENCY_VERSION
        );
        
        wp_enqueue_script(
            'super-agency-admin',
            get_template_directory_uri() . '/assets/js/admin-script.js',
            array('jquery'),
            SUPER_AGENCY_VERSION,
            true
        );
        
        // Get installed plugins list
        $installed_plugins = $this->get_installed_plugins_list();
        
        wp_localize_script('super-agency-admin', 'superAgencyAdmin', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('super_agency_nonce'),
            'customizer_url' => admin_url('customize.php'),
            'site_editor_url' => admin_url('site-editor.php'),
            'support_url' => 'https://wordpress.org/support/theme/super-agency/',
            'docs_url' => 'https://docs.super-agency.com/',
            'installed_plugins' => $installed_plugins,
            'strings' => array(
                'installing' => __('Installing...', 'super-agency'),
                'installed' => __('Installed ✓', 'super-agency'),
                'install_failed' => __('Installation failed', 'super-agency'),
                'loading' => __('Loading plugins...', 'super-agency'),
            )
        ));
    }
    
    /**
     * Get predefined plugins instead of API call
     */
    public function get_predefined_plugins() {
        check_ajax_referer('super_agency_nonce', 'nonce');
        
        if (!current_user_can('install_plugins')) {
            wp_die(__('You do not have sufficient permissions to install plugins.', 'super-agency'));
        }
        
        $plugins = $this->get_super_agency_plugins();
        wp_send_json_success($plugins);
    }
    
    /**
     * Get Super Agency recommended plugins
     */
    private function get_super_agency_plugins() {
        return array(
            array(
                'name' => 'Super Web Share',
                'slug' => 'super-web-share',
                'version' => '1.2.0',
                'author' => 'josevarghese',
                'short_description' => 'Super Web Share helps you easily add a native share prompt to your website, allowing you to share a page or post in less than a minute.',
                'download_link' => 'https://wordpress.org/plugins/super-web-share/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Copy Link to Heading',
                'slug' => 'copy-link-to-heading',
                'version' => '2.1.3',
                'author' => 'josevarghese',
                'short_description' => 'The Copy Link to Heading plugin automatically adds a small, unobtrusive link icon next to the headings in your posts, pages, or custom post types.',
                'download_link' => 'https://wordpress.org/plugins/copy-link-to-heading/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Leaving Notice Popup For External Links',
                'slug' => 'leaving-notice-popup-for-external-links',
                'version' => '1.8.2',
                'author' => 'josevarghese',
                'short_description' => 'Show a customizable popup notice when visitors click on external links, with options to continue or stay on your site.',
                'download_link' => 'https://wordpress.org/plugins/leaving-notice-popup-for-external-links/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Click to Read More Button',
                'slug' => 'click-to-read-more-button',
                'version' => '',
                'author' => 'josevarghese',
                'short_description' => 'Add a customizable "Read More" button to your posts and pages to encourage visitors to continue reading your content.',
                'download_link' => 'https://wordpress.org/plugins/click-to-read-more-button/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Creative Scroll to Top Button',
                'slug' => 'creative-scroll-to-top-button',
                'version' => '',
                'author' => 'josevarghese',
                'short_description' => 'Add a beautiful and customizable scroll-to-top button to your website for a better user experience.',
                'download_link' => 'https://wordpress.org/plugins/creative-scroll-to-top-button/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Super Custom Right Click Menu',
                'slug' => 'super-custom-right-click-menu',
                'version' => '',
                'author' => 'josevarghese',
                'short_description' => 'Replace the default browser right-click context menu with a custom branded menu featuring your own links and actions.',
                'download_link' => 'https://wordpress.org/plugins/super-custom-right-click-menu/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            ),
            array(
                'name' => 'Mobile Smart App Banner',
                'slug' => 'mobile-smart-app-banner',
                'version' => '3.0.1',
                'author' => 'josevarghese',
                'short_description' => 'Transform your mobile website visitors into app users with intelligent smart app banners that boost downloads across iOS and Android devices.',
                'download_link' => 'https://wordpress.org/plugins/mobile-smart-app-banner/',
                'icons' => array(
                    '1x' => '',
                    '2x' => ''
                )
            )
        );
    }
    
    /**
     * Get list of installed plugins
     */
    private function get_installed_plugins_list() {
        if (!function_exists('get_plugins')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        
        $all_plugins = get_plugins();
        $installed_slugs = array();
        
        // Get slugs of our recommended plugins that are installed
        $recommended_plugins = $this->get_super_agency_plugins();
        
        foreach ($recommended_plugins as $plugin) {
            $plugin_slug = $plugin['slug'];
            
            // Check if plugin is installed by looking for the main plugin file
            foreach ($all_plugins as $plugin_file => $plugin_data) {
                // Extract the folder name (slug) from the plugin file path
                $plugin_folder = dirname($plugin_file);
                
                if ($plugin_folder === $plugin_slug || $plugin_file === $plugin_slug . '/' . $plugin_slug . '.php') {
                    $installed_slugs[] = $plugin_slug;
                    break;
                }
            }
        }
        
        return $installed_slugs;
    }
    
    /**
     * Install plugin via AJAX
     */
    public function install_plugin() {
        check_ajax_referer('super_agency_nonce', 'nonce');
        
        if (!current_user_can('install_plugins')) {
            wp_send_json_error(array(
                'message' => __('You do not have sufficient permissions to install plugins.', 'super-agency')
            ));
        }
        
        $plugin_slug = sanitize_text_field($_POST['plugin_slug']);
        
        if (empty($plugin_slug)) {
            wp_send_json_error(array(
                'message' => __('Plugin slug is required.', 'super-agency')
            ));
        }
        
        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
        
        $api = plugins_api('plugin_information', array(
            'slug' => $plugin_slug,
            'fields' => array(
                'short_description' => false,
                'sections' => false,
                'requires' => false,
                'rating' => false,
                'ratings' => false,
                'downloaded' => false,
                'last_updated' => false,
                'added' => false,
                'tags' => false,
                'compatibility' => false,
                'homepage' => false,
                'donate_link' => false,
            ),
        ));
        
        if (is_wp_error($api)) {
            wp_send_json_error(array(
                'message' => $api->get_error_message()
            ));
        }
        
        $upgrader = new Plugin_Upgrader(new WP_Ajax_Upgrader_Skin());
        $install_result = $upgrader->install($api->download_link);
        
        if (is_wp_error($install_result)) {
            wp_send_json_error(array(
                'message' => $install_result->get_error_message()
            ));
        } elseif ($install_result === false) {
            wp_send_json_error(array(
                'message' => __('Plugin installation failed.', 'super-agency')
            ));
        } else {
            wp_send_json_success(array(
                'message' => __('Plugin installed successfully!', 'super-agency')
            ));
        }
    }
    
    /**
     * Get theme changelog
     */
    private function get_changelog() {
        return array(
            '1.0.7.2' => array(
                'date' => 'Current Version',
                'changes' => array(
                    'Added sticky header setting — header is sticky by default, toggleable via Appearance > Super Agency > Settings',
                    'Added scroll-triggered box shadow to sticky header for depth when page is scrolled',
                )
            ),
            '1.0.7' => array(
                'date' => '2026',
                'changes' => array(
                    'Suppressed third-party plugin and theme admin notices from appearing on the Super Agency settings page',
                )
            ),
            '1.0.6' => array(
                'date' => '2026',
                'changes' => array(
                    'Added Getting Started onboarding tab with 7-step setup guide',
                    'Converted footer link columns to Navigation blocks for easy editing in Site Editor',
                    'Converted footer legal links (Terms / Privacy) to a Navigation block',
                    'Fixed header navigation spacing breaking after Gutenberg edits',
                    'Added full link color control: visited, active, focus states via theme.json',
                    'Added link-visited and link-active palette colors',
                    'Removed underlines from default link state; underline now shows on hover only',
                    'Fixed :visited and :active link colors being overridden by higher-specificity CSS',
                    'Removed duplicate CSS rule blocks in blog archive section',
                    'Fixed transform on inline anchor elements in footer (added display: inline-block)',
                    'Added prefers-reduced-motion support — all animations disabled for motion-sensitive users',
                    'Added :focus-visible styles for navigation links, buttons, social links, and pagination',
                    'Fixed outline: none on FAQ accordion summary — keyboard users now get a visible focus ring',
                    'Improved form input focus indicator to meet WCAG 2.4.11 contrast requirements',
                    'Added skip-to-content link styles for keyboard accessibility',
                    'Added Windows High Contrast Mode support via forced-colors media query',
                    'Synced version constant in functions.php with theme version in style.css',
                )
            ),
            '1.0.5' => array(
                'date' => '2025',
                'changes' => array(
                    'The pattern \'Services\' now supports color selection',
                    'Improved theme settings page with tabbed interface',
                    'Enhanced plugin integration for better compatibility',
                    'Updated documentation and support links',
                    'Added professional admin settings page',
                    'Improved accessibility features'
                )
            ),
            '1.0.4' => array(
                'date' => 'Previous Version',
                'changes' => array(
                    'Enhanced service card pattern with better color support',
                    'Fixed mobile responsiveness issues',
                    'Improved accessibility features',
                    'Performance optimizations',
                    'Updated editor styles',
                    'Better WordPress 6.4 compatibility'
                )
            ),
            '1.0.0' => array(
                'date' => 'Initial Release',
                'changes' => array(
                    'Initial release with 13 custom block patterns',
                    '3 style variations (White, Blue, Black)',
                    'Full Site Editing support',
                    'Hero banner pattern',
                    'Services showcase pattern',
                    'Portfolio grid pattern',
                    'Team members pattern',
                    'Client logos pattern',
                    'FAQ accordion pattern',
                    'Call-to-action patterns',
                    'Blog archive pattern',
                    'Responsive design implementation',
                    'Accessibility features',
                    'SEO compatibility'
                )
            )
        );
    }
    
    /**
     * Settings page HTML
     */
    public function settings_page() {
        $current_theme = wp_get_theme();
        $theme_version = $current_theme->get('Version');
        $changelog = $this->get_changelog();
        ?>
        <div class="wrap super-agency-settings">
            <div class="super-agency-header">
                <h1>
                    <span class="theme-icon">SA</span>
                    <?php esc_html_e('Super Agency Theme Settings', 'super-agency'); ?>
                    <span class="version-badge">v<?php echo esc_html($theme_version); ?></span>
                </h1>
                <p><?php esc_html_e('Professional WordPress theme designed for agencies and creative portfolios', 'super-agency'); ?></p>
            </div>

            <?php
            $active_tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'getting-started';
            $saved      = isset($_GET['saved']) && $_GET['saved'] === '1';
            ?>
            <?php if ($saved) : ?>
            <div class="notice notice-success is-dismissible" style="margin: 12px 0;">
                <p><?php esc_html_e('Settings saved.', 'super-agency'); ?></p>
            </div>
            <?php endif; ?>

            <div class="nav-tab-wrapper">
                <a href="#getting-started" class="nav-tab <?php echo $active_tab === 'getting-started' ? 'nav-tab-active' : ''; ?>" data-tab="getting-started">
                    <span class="dashicons dashicons-flag"></span>
                    <?php esc_html_e('Getting Started', 'super-agency'); ?>
                </a>
                <a href="#theme-settings" class="nav-tab <?php echo $active_tab === 'theme-settings' ? 'nav-tab-active' : ''; ?>" data-tab="theme-settings">
                    <span class="dashicons dashicons-admin-settings"></span>
                    <?php esc_html_e('Settings', 'super-agency'); ?>
                </a>
                <a href="#home" class="nav-tab <?php echo $active_tab === 'home' ? 'nav-tab-active' : ''; ?>" data-tab="home">
                    <span class="dashicons dashicons-admin-home"></span>
                    <?php esc_html_e('Quick Links', 'super-agency'); ?>
                </a>
                <a href="#plugins" class="nav-tab <?php echo $active_tab === 'plugins' ? 'nav-tab-active' : ''; ?>" data-tab="plugins">
                    <span class="dashicons dashicons-admin-plugins"></span>
                    <?php esc_html_e('Useful Plugins', 'super-agency'); ?>
                </a>
                <a href="#changelog" class="nav-tab <?php echo $active_tab === 'changelog' ? 'nav-tab-active' : ''; ?>" data-tab="changelog">
                    <span class="dashicons dashicons-clipboard"></span>
                    <?php esc_html_e('Changelog', 'super-agency'); ?>
                </a>
            </div>

            <div class="tab-content" data-active-tab="<?php echo esc_attr($active_tab); ?>">
                <!-- Getting Started Tab -->
                <div id="getting-started" class="tab-panel <?php echo $active_tab === 'getting-started' ? 'active' : ''; ?>">
                    <h2><?php esc_html_e('Getting Started', 'super-agency'); ?></h2>
                    <p class="tab-description"><?php esc_html_e('Follow these steps to set up your site. All editing happens inside the Site Editor — not the old Appearance > Menus or Customizer.', 'super-agency'); ?></p>

                    <div class="super-agency-notice" style="background:#fff3cd;border-left:4px solid #f59e0b;padding:12px 16px;margin-bottom:24px;border-radius:0 6px 6px 0;">
                        <strong><?php esc_html_e('Important:', 'super-agency'); ?></strong>
                        <?php esc_html_e('Super Agency is a Full Site Editing (FSE) theme. Navigation menus and footer links are edited directly in the Site Editor — Appearance > Menus is not used.', 'super-agency'); ?>
                    </div>

                    <div class="setup-steps">
                        <div class="setup-step">
                            <div class="step-number">1</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Add your logo', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('Go to the Header template part and click the logo placeholder to upload your own.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Fheader&canvas=edit')); ?>" class="card-button">
                                    <?php esc_html_e('Edit Header', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>

                        <div class="setup-step">
                            <div class="step-number">2</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Set up your header navigation', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('Open the Header in the Site Editor, click any navigation link, then use the toolbar to edit the label and URL. Add or remove links using the block inserter inside the Navigation block.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Fheader&canvas=edit')); ?>" class="card-button">
                                    <?php esc_html_e('Edit Navigation', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>

                        <div class="setup-step">
                            <div class="step-number">3</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Set up your footer links', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('Open the Footer in the Site Editor. Each column (Services, Company, Resources) contains a Navigation block — click any link to edit its label and URL. You can also add or remove links freely.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Ffooter&canvas=edit')); ?>" class="card-button">
                                    <?php esc_html_e('Edit Footer Links', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>

                        <div class="setup-step">
                            <div class="step-number">4</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Update social media links', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('In the Footer editor, click each social icon to set the URL for your Twitter, LinkedIn, Instagram, and Dribbble profiles.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Ffooter&canvas=edit')); ?>" class="card-button">
                                    <?php esc_html_e('Edit Social Links', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>

                        <div class="setup-step">
                            <div class="step-number">5</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Choose a style variation', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('Pick from White, Blue, or Black color schemes. You can also fine-tune individual colors and typography in the Styles panel.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fstyles&section=%2Fvariations')); ?>" class="card-button">
                                    <?php esc_html_e('Browse Styles', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>

                        <div class="setup-step">
                            <div class="step-number">6</div>
                            <div class="step-content">
                                <h3><?php esc_html_e('Add your content', 'super-agency'); ?></h3>
                                <p><?php esc_html_e('Edit the homepage by opening Templates > Front Page in the Site Editor, or create pages and posts from the WordPress admin. Replace placeholder images and text with your own.', 'super-agency'); ?></p>
                                <a href="<?php echo esc_url(admin_url('post-new.php?post_type=page')); ?>" class="card-button">
                                    <?php esc_html_e('Create a Page', 'super-agency'); ?>
                                </a>
                            </div>
                        </div>
                    </div>

                    <div class="super-agency-notice" style="background:#d1fae5;border-left:4px solid #10b981;padding:12px 16px;margin-top:24px;border-radius:0 6px 6px 0;">
                        <strong><?php esc_html_e('Tip:', 'super-agency'); ?></strong>
                        <?php esc_html_e('All changes in the Site Editor are previewed live before saving. Click Save at the top right to publish your changes.', 'super-agency'); ?>
                    </div>
                </div>

                <!-- Settings Tab -->
                <div id="theme-settings" class="tab-panel <?php echo $active_tab === 'theme-settings' ? 'active' : ''; ?>">
                    <h2><?php esc_html_e('Theme Settings', 'super-agency'); ?></h2>
                    <p class="tab-description"><?php esc_html_e('Configure general theme options to control the behaviour of your site.', 'super-agency'); ?></p>

                    <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
                        <input type="hidden" name="action" value="super_agency_save_settings">
                        <?php wp_nonce_field('super_agency_save_settings'); ?>

                        <table class="form-table" role="presentation">
                            <tbody>
                                <tr>
                                    <th scope="row">
                                        <label for="sticky_header"><?php esc_html_e('Sticky Header', 'super-agency'); ?></label>
                                    </th>
                                    <td>
                                        <label>
                                            <input type="checkbox" id="sticky_header" name="sticky_header" value="yes"
                                                <?php checked(get_option('super_agency_sticky_header', 'yes'), 'yes'); ?>>
                                            <?php esc_html_e('Keep the header fixed at the top of the page while scrolling', 'super-agency'); ?>
                                        </label>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <?php submit_button(__('Save Settings', 'super-agency')); ?>
                    </form>
                </div>

                <!-- Home Tab -->
                <div id="home" class="tab-panel <?php echo $active_tab === 'home' ? 'active' : ''; ?>">
                    <h2><?php esc_html_e('Welcome to Super Agency', 'super-agency'); ?></h2>
                    <p class="tab-description"><?php esc_html_e('Customize your website and manage your theme settings from here. Access quick links to the most important customization options.', 'super-agency'); ?></p>
                    
                    <div class="cards-grid">
                        <div class="settings-card" data-action="style-variations">
                            <div class="card-icon">
                                <span class="dashicons dashicons-art"></span>
                            </div>
                            <h3><?php esc_html_e('Style Variations', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Choose from multiple pre-designed style variations including Blue, Black, and White themes.', 'super-agency'); ?></p>
                            <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fstyles&section=%2Fvariations')); ?>" class="card-button">
                                <?php esc_html_e('Browse Styles', 'super-agency'); ?>
                            </a>
                        </div>

                        <div class="settings-card" data-action="typography">
                            <div class="card-icon">
                                <span class="dashicons dashicons-editor-textcolor"></span>
                            </div>
                            <h3><?php esc_html_e('Typography', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Customize fonts, font sizes, and typography settings to match your brand identity.', 'super-agency'); ?></p>
                            <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fstyles&section=%2Ftypography')); ?>" class="card-button">
                                <?php esc_html_e('Edit Typography', 'super-agency'); ?>
                            </a>
                        </div>

                        <div class="settings-card" data-action="header-customizer">
                            <div class="card-icon">
                                <span class="dashicons dashicons-admin-customizer"></span>
                            </div>
                            <h3><?php esc_html_e('Header Customizer', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Customize your site header, logo, navigation menu, and header styling options.', 'super-agency'); ?></p>
                            <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Fheader&canvas=edit')); ?>" class="card-button">
                                <?php esc_html_e('Customize Header', 'super-agency'); ?>
                            </a>
                        </div>

                        <div class="settings-card" data-action="footer-customizer">
                            <div class="card-icon">
                                <span class="dashicons dashicons-editor-insertmore"></span>
                            </div>
                            <h3><?php esc_html_e('Footer Customizer', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Configure your footer content, widgets, copyright text, and footer layout settings.', 'super-agency'); ?></p>
                            <a href="<?php echo esc_url(admin_url('site-editor.php?p=%2Fwp_template_part%2Fsuper-agency%2F%2Ffooter&canvas=edit')); ?>" class="card-button">
                                <?php esc_html_e('Customize Footer', 'super-agency'); ?>
                            </a>
                        </div>

                        <div class="settings-card" data-action="support">
                            <div class="card-icon">
                                <span class="dashicons dashicons-sos"></span>
                            </div>
                            <h3><?php esc_html_e('Get Support', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Need help? Get professional support, submit feature requests, or report issues.', 'super-agency'); ?></p>
                            <a href="https://wordpress.org/support/theme/super-agency/" target="_blank" class="card-button">
                                <?php esc_html_e('Contact Support', 'super-agency'); ?>
                            </a>
                        </div>

                        <div class="settings-card" data-action="site-editor">
                            <div class="card-icon">
                                <span class="dashicons dashicons-edit"></span>
                            </div>
                            <h3><?php esc_html_e('Site Editor', 'super-agency'); ?></h3>
                            <p><?php esc_html_e('Access the full site editing experience to customize templates and patterns.', 'super-agency'); ?></p>
                            <a href="<?php echo esc_url(admin_url('site-editor.php')); ?>" class="card-button">
                                <?php esc_html_e('Open Site Editor', 'super-agency'); ?>
                            </a>
                        </div>
                    </div>
                </div>

                <!-- Plugins Tab -->
                <div id="plugins" class="tab-panel <?php echo $active_tab === 'plugins' ? 'active' : ''; ?>">
                    <h2><?php esc_html_e('Recommended Plugins', 'super-agency'); ?></h2>
                    <p class="tab-description"><?php esc_html_e('Enhance your website with these carefully selected plugins that work perfectly with Super Agency theme.', 'super-agency'); ?></p>
                    
                    <div id="plugins-container">
                        <div class="loading">
                            <div class="spinner"></div>
                            <p><?php esc_html_e('Loading recommended plugins...', 'super-agency'); ?></p>
                        </div>
                    </div>
                </div>

                <!-- Changelog Tab -->
                <div id="changelog" class="tab-panel <?php echo $active_tab === 'changelog' ? 'active' : ''; ?>">
                    <h2><?php esc_html_e('Theme Changelog', 'super-agency'); ?></h2>
                    <p class="tab-description"><?php esc_html_e('Track all updates, improvements, and bug fixes for Super Agency theme.', 'super-agency'); ?></p>
                    
                    <div class="changelog">
                        <?php foreach ($changelog as $version => $details) : ?>
                        <div class="changelog-item">
                            <div class="changelog-version">
                                <span class="version-number">v<?php echo esc_html($version); ?></span>
                                <span class="version-date"><?php echo esc_html($details['date']); ?></span>
                            </div>
                            <div class="changelog-content">
                                <ul>
                                    <?php foreach ($details['changes'] as $change) : ?>
                                    <li><?php echo esc_html($change); ?></li>
                                    <?php endforeach; ?>
                                </ul>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
}

// Initialize the settings page
new Super_Agency_Settings();