(function (){
'use strict';
function setLegacyState(item, open){
var button=item.querySelector('.redesim-faq-item__question');
var answer=item.querySelector('.redesim-faq-item__answer');
if(!button||!answer){
return;
}
item.classList.toggle('is-open', open);
button.setAttribute('aria-expanded', open ? 'true':'false');
answer.setAttribute('aria-hidden', open ? 'false':'true');
answer.style.maxHeight=open ? answer.scrollHeight + 'px':'';
}
function initLegacyFaq(root){
if(!root||root.dataset.redesimLegacyReady==='1'){
return;
}
root.dataset.redesimLegacyReady='1';
var items=Array.prototype.slice.call(root.querySelectorAll('.redesim-faq-item')
);
var allowMultiple=root.dataset.allowMultiple==='1';
var openFirst=root.dataset.openFirst==='1';
items.forEach(function (item, index){
var button=item.querySelector('.redesim-faq-item__question');
if(!button){
return;
}
setLegacyState(item, openFirst&&index===0);
button.addEventListener('click', function (){
var willOpen = !item.classList.contains('is-open');
if(willOpen&&!allowMultiple){
items.forEach(function (otherItem){
if(otherItem!==item){
setLegacyState(otherItem, false);
}});
}
setLegacyState(item, willOpen);
});
});
}
function init(){
document
.querySelectorAll('.wp-block-redesim-faq.redesim-faq')
.forEach(initLegacyFaq);
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded', init);
}else{
init();
}})();