import{E as EventHandler,f as getSelectorFromElement,S as SelectorEngine,d as defineJQueryPlugin,B as BaseComponent,D as Data,r as reflow,c as getElementFromSelector,M as Manipulator,h as getElement,a as typeCheckConfig}from"./dom.min.js?5.1.3";const NAME="collapse",DATA_KEY="bs.collapse",EVENT_KEY=".bs.collapse",DATA_API_KEY=".data-api",Default={toggle:!0,parent:null},DefaultType={toggle:"boolean",parent:"(null|element)"},EVENT_SHOW="show.bs.collapse",EVENT_SHOWN="shown.bs.collapse",EVENT_HIDE="hide.bs.collapse",EVENT_HIDDEN="hidden.bs.collapse",EVENT_CLICK_DATA_API="click.bs.collapse.data-api",CLASS_NAME_SHOW="show",CLASS_NAME_COLLAPSE="collapse",CLASS_NAME_COLLAPSING="collapsing",CLASS_NAME_COLLAPSED="collapsed",CLASS_NAME_DEEPER_CHILDREN=":scope .collapse .collapse",CLASS_NAME_HORIZONTAL="collapse-horizontal",WIDTH="width",HEIGHT="height",SELECTOR_ACTIVES=".collapse.show, .collapse.collapsing",SELECTOR_DATA_TOGGLE='[data-bs-toggle="collapse"]';class Collapse extends BaseComponent{constructor(e,t){super(e),this._isTransitioning=!1,this._config=this._getConfig(t),this._triggerArray=[];const s=SelectorEngine.find(SELECTOR_DATA_TOGGLE);for(let e=0,t=s.length;ee===this._element));null!==n&&i.length&&(this._selector=n,this._triggerArray.push(t))}this._initializeChildren(),this._config.parent||this._addAriaAndCollapsedClass(this._triggerArray,this._isShown()),this._config.toggle&&this.toggle()}static get Default(){return Default}static get NAME(){return NAME}toggle(){this._isShown()?this.hide():this.show()}show(){if(this._isTransitioning||this._isShown())return;let e,t=[];if(this._config.parent){const e=SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN,this._config.parent);t=SelectorEngine.find(SELECTOR_ACTIVES,this._config.parent).filter((t=>!e.includes(t)))}const s=SelectorEngine.findOne(this._selector);if(t.length){const n=t.find((e=>s!==e));if(e=n?Collapse.getInstance(n):null,e&&e._isTransitioning)return}if(EventHandler.trigger(this._element,EVENT_SHOW).defaultPrevented)return;t.forEach((t=>{s!==t&&Collapse.getOrCreateInstance(t,{toggle:!1}).hide(),e||Data.set(t,DATA_KEY,null)}));const n=this._getDimension();this._element.classList.remove("collapse"),this._element.classList.add("collapsing"),this._element.style[n]=0,this._addAriaAndCollapsedClass(this._triggerArray,!0),this._isTransitioning=!0;const i=`scroll${n[0].toUpperCase()+n.slice(1)}`;this._queueCallback((()=>{this._isTransitioning=!1,this._element.classList.remove("collapsing"),this._element.classList.add("collapse","show"),this._element.style[n]="",EventHandler.trigger(this._element,EVENT_SHOWN)}),this._element,!0),this._element.style[n]=`${this._element[i]}px`}hide(){if(this._isTransitioning||!this._isShown())return;if(EventHandler.trigger(this._element,EVENT_HIDE).defaultPrevented)return;const e=this._getDimension();this._element.style[e]=`${this._element.getBoundingClientRect()[e]}px`,reflow(this._element),this._element.classList.add("collapsing"),this._element.classList.remove("collapse","show");const t=this._triggerArray.length;for(let e=0;e{this._isTransitioning=!1,this._element.classList.remove("collapsing"),this._element.classList.add("collapse"),EventHandler.trigger(this._element,EVENT_HIDDEN)}),this._element,!0)}_isShown(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._element).classList.contains("show")}_getConfig(e){return(e={...Default,...Manipulator.getDataAttributes(this._element),...e}).toggle=Boolean(e.toggle),e.parent=getElement(e.parent),typeCheckConfig(NAME,e,DefaultType),e}_getDimension(){return this._element.classList.contains("collapse-horizontal")?WIDTH:HEIGHT}_initializeChildren(){if(!this._config.parent)return;const e=SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN,this._config.parent);SelectorEngine.find(SELECTOR_DATA_TOGGLE,this._config.parent).filter((t=>!e.includes(t))).forEach((e=>{const t=getElementFromSelector(e);t&&this._addAriaAndCollapsedClass([e],this._isShown(t))}))}_addAriaAndCollapsedClass(e,t){e.length&&e.forEach((e=>{t?e.classList.remove("collapsed"):e.classList.add("collapsed"),e.setAttribute("aria-expanded",t)}))}static jQueryInterface(e){return this.each((function(){const t={};"string"==typeof e&&/show|hide/.test(e)&&(t.toggle=!1);const s=Collapse.getOrCreateInstance(this,t);if("string"==typeof e){if(void 0===s[e])throw new TypeError(`No method named "${e}"`);s[e]()}}))}}if(EventHandler.on(document,EVENT_CLICK_DATA_API,SELECTOR_DATA_TOGGLE,(function(e){("A"===e.target.tagName||e.delegateTarget&&"A"===e.delegateTarget.tagName)&&e.preventDefault();const t=getSelectorFromElement(this);SelectorEngine.find(t).forEach((e=>{Collapse.getOrCreateInstance(e,{toggle:!1}).toggle()}))})),defineJQueryPlugin(Collapse),window.bootstrap=window.bootstrap||{},window.bootstrap.Collapse=Collapse,Joomla&&Joomla.getOptions){const e={...Joomla.getOptions("bootstrap.collapse"),...Joomla.getOptions("bootstrap.accordion")};Object.keys(e).forEach((t=>{const s=e[t],n={toggle:!s.toggle||s.toggle};s.parent&&(n.parent=s.parent);const i=Array.from(document.querySelectorAll(t));i.length&&i.map((e=>new window.bootstrap.Collapse(e,n)))}))}export{Collapse as C};