/**
 * VMP Security - Premium Upgrade Button Handler
 * 
 * Handles "UPGRADE TO PREMIUM" button clicks across all plugin pages.
 * Redirects to Global Options page with License Management section.
 * 
 * @package VMPFence
 * @since 2.0.0
 * @since 2.1.0 Updated to redirect to Global Options page instead of dashboard scroll
 */

(function($) {
    'use strict';

    /**
     * Navigate to All Options page with Global Options section
     */
    function navigateToGlobalOptions() {
        // Redirect to All Options page with hash to Global Options section
        const globalOptionsUrl = new URL(window.location.origin + window.location.pathname);
        globalOptionsUrl.searchParams.set('page', 'vmpfence-all-options');
        globalOptionsUrl.hash = 'vmpfence-global-options';
        window.location.href = globalOptionsUrl.toString();
    }

    /**
     * Initialize upgrade button handlers
     */
    function initUpgradeButtons() {
        // Handle all upgrade button clicks with event delegation
        $(document).on('click', '.vmpfence-premium-upgrade-btn, .vmpfence-scan-premium-upgrade-btn, .vmpfence-btn-upgrade, a[href="#"].button.button-primary', function(e) {
            e.preventDefault();
            
            // Check if this is actually an upgrade button (for generic selector)
            const buttonText = $(this).text().trim().toLowerCase();
            if (buttonText.includes('upgrade to premium') || buttonText.includes('upgrade')) {
                navigateToGlobalOptions();
            }
        });
    }

    // Initialize on document ready
    $(document).ready(function() {
        initUpgradeButtons();
    });

})(jQuery);
