jQuery(document).ready(function () {
    // Function to update URL parameter
    function updateURLParam(param, value) {
        const url = new URL(window.location.href);
        if (value) {
            url.searchParams.set(param, value); // Add or update parameter
        } else {
            url.searchParams.delete(param); // Remove parameter
        }
        window.history.pushState({}, '', url); // Update the URL without reloading
    }

    // Function to toggle sections and update the URL
    function toggleSections(activeTab, inactiveTab, menuValue) {
        jQuery(activeTab.section).show();
        jQuery(activeTab.header).addClass("integrazo_fwcrm_form-settings-heading-active");
        jQuery(inactiveTab.section).hide();
        jQuery(inactiveTab.header).removeClass("integrazo_fwcrm_form-settings-heading-active");
        updateURLParam('menu', menuValue); // Update the URL
    }

    // Define tabs
    const settingsTab = {
        section: "#integrazo_fwcrm_form-settings-section",
        header: "#integrazo_fwcrm_form-settings-header",
        menuValue: null // No parameter for settings
    };

    const licenseTab = {
        section: "#integrazo_fwcrm_form-license-section",
        header: "#integrazo_fwcrm_form-license-header",
        menuValue: 'license' // 'license' parameter for license tab
    };

    // Check the menu parameter in the URL
    const menuParam = new URLSearchParams(window.location.search).get('menu');
    if (menuParam === 'license') {
        toggleSections(licenseTab, settingsTab, licenseTab.menuValue);
    } else {
        // Default to Settings
        toggleSections(settingsTab, licenseTab, settingsTab.menuValue);
    }

    // Click handlers
    jQuery(settingsTab.header).click(function () {
        toggleSections(settingsTab, licenseTab, settingsTab.menuValue);
    });

    jQuery(licenseTab.header).click(function () {
        toggleSections(licenseTab, settingsTab, licenseTab.menuValue);
    });
});


function showAccount()
{
    jQuery("#integrazo_fwcrm_form-auth-popupOverlay").toggleClass("show");
}
