document.addEventListener('DOMContentLoaded', () => {
    // Get the active shortcode from the URL parameters
    const urlParams = new URLSearchParams(window.location.search);
    if(urlParams.get('shortcode')){
        const activeShortcode = urlParams.get('shortcode');
        // Set the active shortcode from the URL
        document.querySelector(`${activeShortcode}`).classList.add("active");
    }

    // Open settings form
    const tabOpenSettings = document.querySelectorAll(".open-settings");
    tabOpenSettings.forEach(button => {
        button.addEventListener("click", () => {
            // Add active class
            const target = button.getAttribute('data-target');
            document.querySelector(target).classList.add('active');

            // Update the URL parameter for the active tab
            const newUrl = new URL(window.location);
            newUrl.searchParams.set('shortcode', target);
            window.history.pushState({}, '', newUrl);
        });
    });
});