import{E as n,S as m,i as T,e as v,d as k,B as L,k as C,l as H,F as D,r as O,b as p}from"./dom.min.js?5.3.0";const M="modal",B="bs.modal",a=`.${B}`,N=".data-api",I="Escape",$=`hide${a}`,q=`hidePrevented${a}`,E=`hidden${a}`,y=`show${a}`,x=`shown${a}`,J=`resize${a}`,F=`click.dismiss${a}`,R=`mousedown.dismiss${a}`,V=`keydown.dismiss${a}`,P=`click${a}${N}`,b="modal-open",j="fade",w="show",u="modal-static",Y=".modal.show",W=".modal-dialog",z=".modal-body",K='[data-bs-toggle="modal"]',G={backdrop:!0,focus:!0,keyboard:!0},Q={backdrop:"(boolean|string)",focus:"boolean",keyboard:"boolean"};class l extends L{constructor(i,e){super(i,e),this._dialog=m.findOne(W,this._element),this._backdrop=this._initializeBackDrop(),this._focustrap=this._initializeFocusTrap(),this._isShown=!1,this._isTransitioning=!1,this._scrollBar=new C,this._addEventListeners()}static get Default(){return G}static get DefaultType(){return Q}static get NAME(){return M}toggle(i){return this._isShown?this.hide():this.show(i)}show(i){this._isShown||this._isTransitioning||n.trigger(this._element,y,{relatedTarget:i}).defaultPrevented||(this._isShown=!0,this._isTransitioning=!0,this._scrollBar.hide(),document.body.classList.add(b),this._adjustDialog(),this._backdrop.show(()=>this._showElement(i)))}hide(){!this._isShown||this._isTransitioning||n.trigger(this._element,$).defaultPrevented||(this._isShown=!1,this._isTransitioning=!0,this._focustrap.deactivate(),this._element.classList.remove(w),this._queueCallback(()=>this._hideModal(),this._element,this._isAnimated()))}dispose(){n.off(window,a),n.off(this._dialog,a),this._backdrop.dispose(),this._focustrap.deactivate(),super.dispose()}handleUpdate(){this._adjustDialog()}_initializeBackDrop(){return new H({isVisible:!!this._config.backdrop,isAnimated:this._isAnimated()})}_initializeFocusTrap(){return new D({trapElement:this._element})}_showElement(i){document.body.contains(this._element)||document.body.append(this._element),this._element.style.display="block",this._element.removeAttribute("aria-hidden"),this._element.setAttribute("aria-modal",!0),this._element.setAttribute("role","dialog"),this._element.scrollTop=0;const e=m.findOne(z,this._dialog);e&&(e.scrollTop=0),O(this._element),this._element.classList.add(w);const s=()=>{this._config.focus&&this._focustrap.activate(),this._isTransitioning=!1,n.trigger(this._element,x,{relatedTarget:i})};this._queueCallback(s,this._dialog,this._isAnimated())}_addEventListeners(){n.on(this._element,V,i=>{if(i.key===I){if(this._config.keyboard){this.hide();return}this._triggerBackdropTransition()}}),n.on(window,J,()=>{this._isShown&&!this._isTransitioning&&this._adjustDialog()}),n.on(this._element,R,i=>{n.one(this._element,F,e=>{if(!(this._element!==i.target||this._element!==e.target)){if(this._config.backdrop==="static"){this._triggerBackdropTransition();return}this._config.backdrop&&this.hide()}})})}_hideModal(){this._element.style.display="none",this._element.setAttribute("aria-hidden",!0),this._element.removeAttribute("aria-modal"),this._element.removeAttribute("role"),this._isTransitioning=!1,this._backdrop.hide(()=>{document.body.classList.remove(b),this._resetAdjustments(),this._scrollBar.reset(),n.trigger(this._element,E)})}_isAnimated(){return this._element.classList.contains(j)}_triggerBackdropTransition(){if(n.trigger(this._element,q).defaultPrevented)return;const e=this._element.scrollHeight>document.documentElement.clientHeight,s=this._element.style.overflowY;s==="hidden"||this._element.classList.contains(u)||(e||(this._element.style.overflowY="hidden"),this._element.classList.add(u),this._queueCallback(()=>{this._element.classList.remove(u),this._queueCallback(()=>{this._element.style.overflowY=s},this._dialog)},this._dialog),this._element.focus())}_adjustDialog(){const i=this._element.scrollHeight>document.documentElement.clientHeight,e=this._scrollBar.getWidth(),s=e>0;if(s&&!i){const o=p()?"paddingLeft":"paddingRight";this._element.style[o]=`${e}px`}if(!s&&i){const o=p()?"paddingRight":"paddingLeft";this._element.style[o]=`${e}px`}}_resetAdjustments(){this._element.style.paddingLeft="",this._element.style.paddingRight=""}static jQueryInterface(i,e){return this.each(function(){const s=l.getOrCreateInstance(this,i);if(typeof i=="string"){if(typeof s[i]>"u")throw new TypeError(`No method named "${i}"`);s[i](e)}})}}n.on(document,P,K,function(t){const i=m.getElementFromSelector(this);["A","AREA"].includes(this.tagName)&&t.preventDefault(),n.one(i,y,o=>{o.defaultPrevented||n.one(i,E,()=>{T(this)&&this.focus()})});const e=m.findOne(Y);e&&l.getInstance(e).hide(),l.getOrCreateInstance(i).toggle(this)}),v(l),k(l),Joomla=Joomla||{},Joomla.Modal=Joomla.Modal||{},window.bootstrap=window.bootstrap||{},window.bootstrap.Modal=l;const S={iframe:["src","name","width","height"]};if(Joomla.initialiseModal=(t,i)=>{t instanceof Element&&(new window.bootstrap.Modal(t,i),t.open=()=>{window.bootstrap.Modal.getInstance(t).show(t)},t.close=()=>{window.bootstrap.Modal.getInstance(t).hide()},t.addEventListener("show.bs.modal",()=>{if(Joomla.Modal.setCurrent(t),t.dataset.url){const e=t.querySelector(".modal-body"),s=e.querySelector("iframe");if(s){const o=t.querySelector("joomla-field-mediamore");o&&o.parentNode.removeChild(o),s.parentNode.removeChild(s)}if(t.dataset.iframe.indexOf("document.getElementById")>0){const o=t.dataset.iframe.split("+"),r=o[1].split('"');let d;r[0]=r[0].replace(/"/g,'"'),document.getElementById(r[1])?d=document.getElementById(r[1]).value:d=new Function(`return ${r[0]}`).call(null),e.insertAdjacentHTML("afterbegin",Joomla.sanitizeHtml(`${o[0]}${d}${o[2]}`,S))}else e.insertAdjacentHTML("afterbegin",Joomla.sanitizeHtml(t.dataset.iframe,S))}}),t.addEventListener("shown.bs.modal",()=>{const e=t.querySelector(".modal-body"),s=t.querySelector(".modal-header"),o=t.querySelector(".modal-footer");let r=0,d=0,c=0,_=0,f=0;if(e){s&&(r=s.getBoundingClientRect().height,f=e.offsetHeight),o&&(d=parseFloat(getComputedStyle(o,null).height.replace("px","")));const h=parseFloat(getComputedStyle(e,null).height.replace("px","")),g=e.offsetTop,A=parseFloat(getComputedStyle(document.body,null).height.replace("px",""))-g*2;_=f-h,c=A-(r+d+_)}if(t.dataset.url){const h=t.querySelector("iframe");parseFloat(getComputedStyle(h,null).height.replace("px",""))>c&&(e.style.maxHeight=c,e.style.overflowY="auto",h.style.maxHeight=c-_)}}),t.addEventListener("hide.bs.modal",()=>{const e=t.querySelector(".modal-body");e.style.maxHeight="initial"}),t.addEventListener("hidden.bs.modal",()=>{Joomla.Modal.setCurrent("")}))},Joomla.iframeButtonClick=t=>{if(!t.iframeSelector||!t.buttonSelector)throw new Error("Selector is missing");const i=document.querySelector(`${t.iframeSelector} iframe`);if(i){const e=i.contentWindow.document.querySelector(t.buttonSelector);e&&e.click()}},Joomla&&Joomla.getOptions){const t=Joomla.getOptions("bootstrap.modal");typeof t=="object"&&t!==null&&Object.keys(t).forEach(i=>{const e=t[i],s={backdrop:e.backdrop?e.backdrop:!0,keyboard:e.keyboard?e.keyboard:!0,focus:e.focus?e.focus:!0};Array.from(document.querySelectorAll(i)).map(o=>Joomla.initialiseModal(o,s))})}export{l as M};