(()=>{"use strict";const t=class{constructor(t,e=!0,i={}){this.accordion=t,this.editor=e;const s=this.getDataSettings();this.settings={...this.getDefaultSettings(),...s,...i},this.elements=this.getElements(),this.eventListeners=[],this.isAnimating=!1,this.bindEvents(),this.defaultActiveTab()}getDefaultSettings(){return{selectors:{tabTitle:".ablocks-block--single-accordion",tabContent:".ablocks-block--single-accordion__body"},classes:{activeItem:"ablocks-block--single-accordion-is-selected"},toggleSelf:!0,hidePrevious:!0,autoExpand:!0,allowMultiple:!1,initialOpen:0}}getDataSettings(){return{allowMultiple:"true"===this.accordion.getAttribute("data-multiple"),initialOpen:parseInt(this.accordion.getAttribute("data-initial-open"))||0}}getElements(){const{tabTitle:t,tabContent:e}=this.settings.selectors;return{tabTitles:this.queryElements(t),tabContents:this.queryElements(e)}}queryElements(t){return Array.from(this.accordion.querySelectorAll(t))}bindEvents(){this.elements.tabTitles.forEach(t=>{const e=t.querySelector(".ablocks-block--single-accordion__heading"),i=e=>{e.preventDefault(),this.isAnimating||this.changeActiveTab(t.getAttribute("data-id-acc"))};e.addEventListener("click",i),this.eventListeners.push({element:e,handler:i})})}isActiveTab(t){const{activeItem:e}=this.settings.classes,i=this.elements.tabTitles.find(e=>e.getAttribute("data-id-acc")===t);return i&&i.classList.contains(e)}changeActiveTab(t){const e=this.isActiveTab(t),{toggleSelf:i,allowMultiple:s}=this.settings;s?e?this.deactivateTab(t):this.activateTab(t):((!1===this.editor&&!0===i||!e)&&this.deactivateAllTabs(),e||this.activateTab(t))}deactivateAllTabs(){const{activeItem:t}=this.settings.classes;this.elements.tabTitles.forEach(e=>{if(e.classList.contains(t)){const t=e.getAttribute("data-id-acc");this.deactivateTab(t)}})}deactivateTab(t){const{activeItem:e}=this.settings.classes,i=this.elements.tabTitles.find(e=>e.getAttribute("data-id-acc")===t);i&&(i.classList.remove(e),this.slideUp(t))}activateTab(t){const{activeItem:e}=this.settings.classes,i=this.elements.tabTitles.find(e=>e.getAttribute("data-id-acc")===t);i&&(i.classList.add(e),this.slideDown(t))}removeListeners(){this.eventListeners.forEach(({element:t,handler:e})=>{t.removeEventListener("click",e)}),this.eventListeners=[]}defaultActiveTab(){const{initialOpen:t}=this.settings;t>0&&this.activateTab((t-1).toString())}slideDown(t){const e=this.elements.tabContents.find(e=>e.parentElement.getAttribute("data-id-acc")===t),i=e.scrollHeight;this.isAnimating=!0,e.style.height="0px",e.style.display="block",e.style.transition="height 0.4s ease, visibility 0.4s ease",setTimeout(()=>{e.style.height=`${i}px`},10),setTimeout(()=>{e.style.height="auto",e.style.transition="",this.isAnimating=!1},400)}slideUp(t){const e=this.elements.tabContents.find(e=>e.parentElement.getAttribute("data-id-acc")===t);this.isAnimating=!0,e.style.height=`${e.scrollHeight}px`,e.style.transition="height 0.4s ease, visibility 0.4s ease",setTimeout(()=>{e.style.height="0px"},10),setTimeout(()=>{e.style.display="none",e.style.transition="",this.isAnimating=!1},400)}};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".ablocks-block--accordion").forEach(e=>{new t(e,!1)})})})();