jQuery(document).ready(function($) {
    // Get the tab parameter from the URL
    var urlParams = new URLSearchParams(window.location.search);
    var currentPage = urlParams.get('page');
    if (currentPage === 'integrate-with-zoho-desk') {
        var activeTab = urlParams.get('tab') || 'accounts'; // Default to 'auth' tab if no tab parameter is set

        // If no 'tab' parameter exists in the URL, update the URL to include 'auth' as the default
        if (!urlParams.has('tab')) {
            // Append the 'auth' tab to the URL without reloading the page
            urlParams.set('tab', 'accounts');
            window.history.replaceState(null, null, '?' + urlParams.toString());
        }

        // Hide all tab content and remove active class from all tabs
        $('.iafwzdesk-tab').removeClass('iafwzdesk-tab-active');
        $('.iafwzdesk-tab-content').hide();

        // Show the active tab content and add active class to the active tab
        $('#iafwzdesk-tab-' + activeTab).addClass('iafwzdesk-tab-active');
        $('#iafwzdesk-content-' + activeTab).show();
    }
});
