var r=Object.defineProperty;var d=(o,t,s)=>t in o?r(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s;var l=(o,t,s)=>d(o,typeof t!="symbol"?t+"":t,s);import{$ as y}from"./jquery-BJllTr_o.js";const m=()=>{const o=y("[data-modal-close]");o.length&&o.trigger("click")},e=class e{constructor(t,s={}){if(this.id=t.dataset.modalTarget,this.buttonEl=t,this.modal=document.getElementById(this.id),!this.modal){console.warn(`Modal: Element with ID "${this.id}" not found.`);return}this.options=s,this.isOpen=!1,this.componentType="modal",this.zIndex=e.zIndexCounter,this.overlayClose=this.modal.dataset.overlayClose!=="false",this.init()}init(){this.modal&&(this.createSharedOverlay(),this.addEventListeners(),this.moveToBody())}createSharedOverlay(){e.overlay||(e.overlay=document.createElement("div"),e.overlay.classList.add("modal-overlay"),e.overlay.style.position="fixed",e.overlay.style.top="0",e.overlay.style.left="0",e.overlay.style.right="0",e.overlay.style.bottom="0",e.overlay.style.backgroundColor="black",e.overlay.style.opacity="0.8",e.overlay.style.zIndex="99",e.overlay.style.transition="opacity 300ms ease-in-out",e.overlay.style.display="none",document.body.appendChild(e.overlay))}addEventListeners(){const t=this.buttonEl,s=this.modal.querySelectorAll(`[data-${this.componentType}-close="${this.id}"]`),a=this.modal.querySelector(".panel");if(!t||!s||!a){console.warn(`Modal: Missing essential elements for ID "${this.id}"`);return}t.addEventListener("click",()=>this.open()),this.modal.style.display="none",s.forEach(n=>n.addEventListener("click",()=>this.close())),this.modal.addEventListener("click",n=>{!a.contains(n.target)&&this.overlayClose&&this.close()})}open(){!this.modal||this.isOpen||(e.currentTopZIndex+=2,this.zIndex=e.currentTopZIndex,this.isOpen=!0,e.openModals.add(this),this.modal.style.zIndex=this.zIndex,e.overlay.style.zIndex=this.zIndex-1,e.overlay.style.display="block",this.modal.style.transition="opacity 300ms ease, transform 300ms ease",this.modal.style.opacity="0",this.modal.style.transform="translateY(-10%)",this.modal.style.display="block",setTimeout(()=>{this.modal.style.opacity="1",this.modal.style.transform="translateY(0)"},10),document.body.style.overflow="hidden")}close(){!this.modal||!this.isOpen||(this.isOpen=!1,this.modal.style.opacity="0",this.modal.style.transform="translateY(-10%)",setTimeout(()=>{if(e.openModals.delete(this),this.modal.style.display="none",e.openModals.size>0){const t=Array.from(e.openModals),s=t[t.length-1];e.currentTopZIndex=s.zIndex,e.overlay.style.zIndex=s.zIndex-1}else e.overlay.style.display="none",e.currentTopZIndex=e.zIndexCounter,document.body.style.overflow=""},300))}moveToBody(){document.body.prepend(this.modal)}static start(t="[data-modal-target]"){const s=document.querySelectorAll(t);if(s.length)return Array.from(s).map(a=>new e(a))}};l(e,"zIndexCounter",100),l(e,"openModals",new Set),l(e,"overlay",null),l(e,"currentTopZIndex",100);let i=e;export{i as M,m as c};
