(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.KadenceAccordion=b()})(this,function(){"use strict";function a(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function b(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function c(a,c,d){return c&&b(a.prototype,c),d&&b(a,d),a}function d(){return d=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},d.apply(this,arguments)}function e(a){return f(a)||g(a)||h()}function f(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function g(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function h(){throw new TypeError("Invalid attempt to spread non-iterable instance")}(function(){function a(a,b){b=b||{bubbles:!1,cancelable:!1,detail:void 0};var c=document.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c}return"function"!=typeof window.CustomEvent&&void(a.prototype=window.Event.prototype,window.CustomEvent=a)})(),Array.from||(Array.from=function(){var a=Object.prototype.toString,b=function(b){return"function"==typeof b||"[object Function]"===a.call(b)},c=function(a){var b=+a;return isNaN(b)?0:0!=b&&isFinite(b)?(0<b?1:-1)*Math.floor(Math.abs(b)):b},d=Math.pow(2,53)-1,e=function(a){var b=c(a);return Math.min(Math.max(b,0),d)};return function(a){var c=this,d=Object(a);if(null==a)throw new TypeError("Array.from requires an array-like object - not null or undefined");var f,g=1<arguments.length?arguments[1]:void 0;if("undefined"!=typeof g){if(!b(g))throw new TypeError("Array.from: when provided, the second argument must be a function");2<arguments.length&&(f=arguments[2])}for(var h,i=e(d.length),j=b(c)?Object(new c(i)):Array(i),l=0;l<i;)h=d[l],j[l]=g?"undefined"==typeof f?g(h,l):g.call(f,h,l):h,l+=1;return j.length=i,j}}()),function(a){var b=a.body||a.documentElement,c=b.style,d="",e="";""==c.WebkitAnimation&&(d="-webkit-"),""==c.MozAnimation&&(d="-moz-"),""==c.OAnimation&&(d="-o-"),""==c.WebkitTransition&&(e="-webkit-"),""==c.MozTransition&&(e="-moz-"),""==c.OTransition&&(e="-o-"),Object.defineProperty(Object.prototype,"onCSSAnimationEnd",{value:function(a){var b=function c(b){a(),b.target.removeEventListener(b.type,c)};return this.addEventListener("webkitAnimationEnd",b),this.addEventListener("mozAnimationEnd",b),this.addEventListener("oAnimationEnd",b),this.addEventListener("oanimationend",b),this.addEventListener("animationend",b),(""!=d||"animation"in c)&&"0s"!=getComputedStyle(this)[d+"animation-duration"]||a(),this},enumerable:!1,writable:!0}),Object.defineProperty(Object.prototype,"onCSSTransitionEnd",{value:function(a){var b=function c(b){a(),b.target.removeEventListener(b.type,c)};return this.addEventListener("webkitTransitionEnd",b),this.addEventListener("mozTransitionEnd",b),this.addEventListener("oTransitionEnd",b),this.addEventListener("transitionend",b),this.addEventListener("transitionend",b),(""!=e||"transition"in c)&&"0s"!=getComputedStyle(this)[e+"transition-duration"]||a(),this},enumerable:!1,writable:!0})}(document,window,0);var i=function(){function b(c,f){var g=this;a(this,b);var h="string"==typeof c?document.querySelector(c):c;if(null!=h){var i={headerClass:".kt-blocks-accordion-header",panelClass:".kt-accordion-panel",panelInnerClass:".kt-accordion-panel-inner",hiddenClass:"kt-accordion-panel-hidden",activeClass:"kt-accordion-panel-active",get hidenClass(){return this.hiddenClass},initializedClass:"kt-accordion-initialized",get initalisedClass(){return this.initializedClass},headerDataAttr:"data-kt-accordion-header-id",openMultiplePanels:!1,openHeadersOnLoad:[],headerOpenLabel:"",headerCloseLabel:"",roles:!0};this.settings=d({},i,f),this.container=h;var j=Array.from(this.container.children),k=[];Array.from(j).forEach(function(a){Array.from(a.children).forEach(function(a){k.push(a)})});var l=k.filter(function(a){return!a.classList.contains(g.settings.panelClass.substr(1))});this.headers=l.reduce(function(b,c){var d,f=Array.from(c.children).filter(function(a){return a.classList.contains(g.settings.headerClass.substr(1))});return!f.length&&c.children[0]&&c.children[0].children&&c.children[0].children.length&&(f=Array.from(c.children[0].children).filter(function(a){return a.classList.contains(g.settings.headerClass.substr(1))})),b=(d=[]).concat.apply(d,e(b).concat([f])),b},[]),this.panels=k.filter(function(a){return a.classList.contains(g.settings.panelClass.substr(1))}),this.toggleEl=void 0===this.settings.toggleEl?this.headers:Array.from(this.container.querySelectorAll(this.settings.toggleEl)),this.states=[].map.call(this.headers,function(){return{state:"closed"}}),this.ids=[].map.call(this.headers,function(){return{id:Math.floor(1e6*Math.random()+1)}}),this.toggling=!1,this.container?this.init():console.log("Something is wrong with you markup...")}}return c(b,[{key:"init",value:function(){this._setupAttributes(),this._initalState(),this.calculateAllPanelsHeight(),this._insertDataAttrs(),this._addListeners(),this._finishInitialization()}},{key:"_setRole",value:function(a,b){("boolean"==typeof this.settings.roles&&this.settings.roles||void 0!==this.settings.roles[a]&&!1!==this.settings.roles[a])&&b.setAttribute("role",a)}},{key:"_initalState",value:function(){var a=this.settings.openHeadersOnLoad;this.headers.forEach(function(a){a.setAttribute("aria-expanded",!1)}),a.length&&(this.toggling=!0,this._openHeadersOnLoad(a)),this._renderDom()}},{key:"_insertDataAttrs",value:function(){var a=this;this.headers.forEach(function(b,c){b.setAttribute(a.settings.headerDataAttr,c)})}},{key:"_finishInitialization",value:function(){this.container.classList.add(this.settings.initializedClass),this._setRole("presentation",this.container);var a=new CustomEvent("initialized");this.container.dispatchEvent(a)}},{key:"_addListeners",value:function(){var a=this;this.headers.forEach(function(b,c){b.addEventListener("click",function(){a.handleClick(b,c)}),b.addEventListener("keydown",function(b){var d=b.which.toString(),e=b.ctrlKey&&d.match(/33|34/);if(d.match(/38|40/)||e){var f=d.match(/34|40/)?1:-1,g=a.headers.length;a.headers[(c+g+f)%g].focus(),b.preventDefault()}else d.match(/35|36/)&&("36"===d?a.headers[0].focus():"35"===d?a.headers[a.headers.length-1].focus():void 0,b.preventDefault())}),b.addEventListener("startOpen",function(){a.handleClick(b,c,!0)})})}},{key:"handleClick",value:function(a,b,c){c||(c=!1);var d=this,e=this.settings.headerClass.substr(1);if(a.classList.contains(e)&&!1===this.toggling)this.toggling=!0,this.setState(b),this._renderDom();else if(c)var f=setInterval(function(){!1===d.toggling&&(d.toggling=!0,d.setState(b),d._renderDom(),clearInterval(f))},50)}},{key:"setState",value:function(a){var b=this,c=this.getState();this.settings.openMultiplePanels||c.filter(function(b,c){c!=a&&(b.state="closed")}),c.filter(function(c,d){if(d==a){var e=b.toggleState(c.state);return c.state=e}})}},{key:"_renderDom",value:function(){var a=this;this.states.filter(function(b,c){"open"===b.state&&a.open(c,!1)}),this.states.filter(function(b,c){"closed"===b.state&&a.close(c,!1)})}},{key:"open",value:function(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];b&&this.setState(a),this.togglePanel("open",a)}},{key:"close",value:function(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];b&&this.setState(a),this.togglePanel("closed",a)}},{key:"openAll",value:function(){var a=this;this.headers.forEach(function(b,c){a.togglePanel("open",c)})}},{key:"closeAll",value:function(){var a=this;this.headers.forEach(function(b,c){a.togglePanel("closed",c)})}},{key:"togglePanel",value:function(a,b){var c=this;if(void 0!==a&&void 0!==b)if("closed"===a){var d=this.headers[b],e=this.panels[b];if(!e.classList.contains(this.settings.hiddenClass)){e.setAttribute("data-panel-height",e.scrollHeight+"px"),e.style.height=e.scrollHeight+"px",e.offsetHeight,e.style.height="",e.classList.add("kt-panel-is-collapsing"),e.classList.remove(this.settings.activeClass),d.classList.remove(this.settings.activeClass),d.setAttribute("aria-expanded",!1);var f=1e3*parseFloat(getComputedStyle(e).transitionDuration);setTimeout(function(){return e.classList.add(c.settings.hiddenClass),e.classList.remove("kt-panel-is-collapsing"),c.toggling=!1},f)}}else if("open"===a){var g=this.headers[b],h=this.panels[b];if(!h.classList.contains(this.settings.activeClass)){h.classList.remove(this.settings.hiddenClass),h.style.height=0,h.offsetHeight,h.classList.add("kt-panel-is-expanding"),h.style.height=h.scrollHeight<parseInt(h.getAttribute("data-panel-height"))?parseInt(h.getAttribute("data-panel-height"))+"px":h.scrollHeight+"px",h.offsetHeight,g.classList.add(this.settings.activeClass),g.setAttribute("aria-expanded",!0);var i=window.document.createEvent("UIEvents");i.initUIEvent("resize",!0,!1,window,0),window.dispatchEvent(i);var j=1e3*parseFloat(getComputedStyle(h).transitionDuration);setTimeout(function(){return h.classList.add(c.settings.activeClass),h.style.height="",h.classList.remove("kt-panel-is-expanding"),c.toggling=!1},j)}}}},{key:"getState",value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];if(b.length&&Array.isArray(b)){var c=b.map(function(b){return a.states[b]});return c}return this.states}},{key:"toggleState",value:function(a){if(void 0!==a)return"closed"===a?"open":"closed"}},{key:"_openHeadersOnLoad",value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];if(b.length&&Array.isArray(b)){var c=b.filter(function(a){return null!=a});c.forEach(function(b){a.setState(b)})}}},{key:"_setupAttributes",value:function(){this._setupHeaders(),this._setupPanels(),this._insertDataAttrs()}},{key:"_setPanelHeight",value:function(){this.calculateAllPanelsHeight()}},{key:"calculatePanelHeight",value:function(a){var b=a.querySelector(this.settings.panelInnerClass),c=b.getBoundingClientRect();return a.setAttribute("data-panel-height","".concat(c.height,"px"))}},{key:"calculateAllPanelsHeight",value:function(){var a=this;this.panels.forEach(function(b){a.calculatePanelHeight(b)})}},{key:"_setupHeaders",value:function(){var a=this;this.headers.forEach(function(b,c){b.setAttribute("id","kt-accordion-header-".concat(a.ids[c].id)),b.setAttribute("aria-controls","kt-accordion-panel-".concat(a.ids[c].id))})}},{key:"_setupPanels",value:function(){var a=this;this.panels.forEach(function(b,c){b.setAttribute("id","kt-accordion-panel-".concat(a.ids[c].id)),b.setAttribute("aria-labelledby","kt-accordion-header-".concat(a.ids[c].id)),(!0===a.settings.roles||!1!==a.settings.roles.region)&&a._setRole("region",b)})}}]),b}();return i}),function(){"use strict";var a=!1;window.KadenceBlocksAccordion={scroll:function(a,b,c){if(!(0>=c)){var d=b-a.scrollTop;setTimeout(function(){a.scrollTop+=10*(d/c),a.scrollTop===b||scrollTo(a,b,c-10)},10)}},anchor:function(b){if(""!=window.location.hash){var c,d=location.hash.substring(1);if(!/^[A-z0-9_-]+$/.test(d))return;if(b.type&&"initialized"===b.type&&a)return;if(a=!0,c=document.getElementById(d),c&&c.classList.contains("wp-block-kadence-pane")){var e=document.querySelectorAll("#"+d+" .kt-blocks-accordion-header")[0];e.classList.contains("kt-accordion-panel-active")||(b.type&&"initialized"===b.type?window.setTimeout(function(){e.dispatchEvent(new Event("startOpen"))},50):e.dispatchEvent(new Event("startOpen")))}}},init:function(){for(var a=document.querySelectorAll(".kt-accordion-inner-wrap"),c=Array.from(a),d=0,e=c.length;d<e;d++){var f=c[d].getAttribute("data-allow-multiple-open"),g=c[d].getAttribute("data-start-open"),h=parseInt(g);if("none"!==g)for(var j=0,k=c[d].children.length;j<k;j++)if(c[d].children[j].classList.contains("kt-accordion-pane-"+parseInt(1+h))){h=j;break}c[d].addEventListener("initialized",window.KadenceBlocksAccordion.anchor,!1),new KadenceAccordion(c[d],{openHeadersOnLoad:"none"===g?[]:[parseInt(h)],headerClass:".kt-blocks-accordion-header",panelClass:".kt-accordion-panel",panelInnerClass:".kt-accordion-panel-inner",hiddenClass:"kt-accordion-panel-hidden",activeClass:"kt-accordion-panel-active",initializedClass:"kt-accordion-initialized",headerDataAttr:"data-kt-accordion-header-id",openMultiplePanels:!("true"!==f),roles:{presentation:!1,region:!0}})}window.addEventListener("hashchange",window.KadenceBlocksAccordion.anchor,!1)}},"loading"===document.readyState?document.addEventListener("DOMContentLoaded",window.KadenceBlocksAccordion.init):window.KadenceBlocksAccordion.init()}();