window.addEventListener('load', (event) => {
    
    const tabs = document.querySelectorAll('[data-tabs-container]')

    function toggleTab(container, button){
        [...container.querySelectorAll('[data-tab-target]')].forEach((b)=>{b.classList.remove('is-selected')});
        [...container.querySelectorAll('[data-tab-index]')].forEach((t)=>{t.style.display = 'none'});
        button.classList.add('is-selected')
        const target = button.getAttribute('data-tab-target')
        container.querySelector(`[data-tab-index="${target}"]`).style.display = 'block';
        
    }
    
    tabs.forEach(tabContainer => {
        const tabsButtons = tabContainer.querySelectorAll('[data-tab-target]')
        tabsButtons.forEach(button => {
            button.addEventListener('click', function(){
                toggleTab(tabContainer, this)
            })
        })
    })
})