import{b as a}from"./p-b9dddc6c.js";import{j as o,k as t}from"./p-7c87fba4.js";let r=0;const s=o=>{a.hasDocument&&c(document);const t=r++;o.overlayIndex=t,o.el.hasAttribute("id")||(o.el.id=`bal-overlay-${t}`)},e=(a,o)=>(void 0===o&&(o="bal-modal,bal-snackbar,bal-toast"),Array.from(a.querySelectorAll(o)).filter((a=>a.overlayIndex>0))),n=(a,o,t)=>{const r=e(a,o);return void 0===t?r[r.length-1]:r.find((a=>a.id===t))},c=a=>{0===r&&(r=1,a.addEventListener("keyup",(o=>{if("Escape"===o.key){const o=n(a);o&&o.dismiss(void 0,"backdrop")}})))},d=async(a,o,t,r)=>{if(!a.presented)return!1;try{a.el.style.setProperty("pointer-events","none"),a.willDismiss.emit({data:o,role:t}),await r(),a.presented=!1,a.didDismiss.emit({data:o,role:t})}catch(o){a.presented=!1,console.error(o)}return a.el.remove(),!0},i=(a,o)=>{let t;const r=new Promise((a=>t=a));return l(a,o,(a=>{t(a.detail)})),r},l=(a,r,s)=>{const e=o=>{t(a,r,e),s(o)};o(a,r,e)};export{n as a,d,i as e,e as g,s as p}