class PersistTabs {
    init() {

        const tabsStorage = 'activeTabShopyPress';

        let tabs = jQuery('.main-nav-tabs .nav-link');
        let tabPanes = jQuery('.tab-content .tab-pane');
        
        function clearActiveClasses() {
            tabs.removeClass('active');
            tabPanes.removeClass('show active');
        }
        let activeTabId = localStorage.getItem(tabsStorage);
        if (activeTabId) {
            clearActiveClasses();
            let activeTab = jQuery(`.nav-tabs .nav-link[data-bs-target="#${activeTabId}"]`);
            let activeTabContent = jQuery(`#${activeTabId}`);
            if (activeTab.length && activeTabContent.length) {
                activeTab.addClass('active');
                activeTabContent.addClass('show active');
            }
        }
        tabs.on('click', function () {
            clearActiveClasses();
            let targetContentId = jQuery(this).attr('data-bs-target').substring(1);
            jQuery(this).addClass('active');
            jQuery(`#${targetContentId}`).addClass('show active');
            localStorage.setItem(tabsStorage, targetContentId);
        });
    }
}
export default PersistTabs;