import{g as t,c as n}from"./p-fa952096.js";import{a as o,r as e,g as a}from"./p-f8063d7b.js";import{OVERLAY_BACK_BUTTON_PRIORITY as s}from"./p-f2660943.js";let i=0;const r=new WeakMap,c=t=>({create:n=>b(t,n),dismiss:(n,o,e)=>w(document,n,o,t,e),getTop:async()=>g(document,t)}),d=c("ion-alert"),u=c("ion-action-sheet"),p=c("ion-modal"),l=c("ion-picker"),f=c("ion-popover"),m=c("ion-toast"),y=t=>{"undefined"!=typeof document&&h(document);const n=i++;t.overlayIndex=n,t.hasAttribute("id")||(t.id="ion-overlay-"+n)},b=(t,n)=>"undefined"!=typeof customElements?customElements.whenDefined(t).then((()=>{const o=document.createElement(t);return o.classList.add("overlay-hidden"),Object.assign(o,n),B(document).appendChild(o),o.componentOnReady()})):Promise.resolve(),v='[tabindex]:not([tabindex^="-"]), input:not([type=hidden]):not([tabindex^="-"]), textarea:not([tabindex^="-"]), button:not([tabindex^="-"]), select:not([tabindex^="-"]), .ion-focusable:not([tabindex^="-"])',x="input:not([type=hidden]), textarea, button, select",h=t=>{0===i&&(i=1,t.addEventListener("focus",(n=>((t,n)=>{const o=g(n),e=t.target;if(o&&e)if(o===e)o.lastFocus=void 0;else{const t=a(o);if(!t.contains(e))return;const s=t.querySelector(".ion-overlay-wrapper");if(!s)return;if(s.contains(e))o.lastFocus=e;else{const t=o.lastFocus;((t,n)=>{let o=t.querySelector(v);const e=o&&o.shadowRoot;e&&(o=e.querySelector(x)||o),o?o.focus():n.focus()})(s,o),t===n.activeElement&&((t,n)=>{const o=Array.from(t.querySelectorAll(v));let e=o.length>0?o[o.length-1]:null;const a=e&&e.shadowRoot;a&&(e=a.querySelector(x)||e),e?e.focus():n.focus()})(s,o),o.lastFocus=n.activeElement}}})(n,t)),!0),t.addEventListener("ionBackButton",(n=>{const o=g(t);o&&o.backdropDismiss&&n.detail.register(s,(()=>o.dismiss(void 0,I)))})),t.addEventListener("keyup",(n=>{if("Escape"===n.key){const n=g(t);n&&n.backdropDismiss&&n.dismiss(void 0,I)}})))},w=(t,n,o,e,a)=>{const s=g(t,e,a);return s?s.dismiss(n,o):Promise.reject("overlay does not exist")},g=(t,n,o)=>{const e=((t,n)=>(void 0===n&&(n="ion-alert,ion-action-sheet,ion-loading,ion-modal,ion-picker,ion-popover,ion-toast"),Array.from(t.querySelectorAll(n)).filter((t=>t.overlayIndex>0))))(t,n);return void 0===o?e[e.length-1]:e.find((t=>t.id===o))},k=async(o,e,a,s,i)=>{if(o.presented)return;o.presented=!0,o.willPresent.emit();const r=t(o),c=o.enterAnimation?o.enterAnimation:n.get(e,"ios"===r?a:s);await E(o,c,o.el,i)&&o.didPresent.emit(),"ION-TOAST"!==o.el.tagName&&j(o.el),o.keyboardClose&&o.el.focus()},j=async t=>{let n=document.activeElement;if(!n)return;const o=n&&n.shadowRoot;o&&(n=o.querySelector(x)||n),await t.onDidDismiss(),n.focus()},A=async(o,e,a,s,i,c,d)=>{if(!o.presented)return!1;o.presented=!1;try{o.el.style.setProperty("pointer-events","none"),o.willDismiss.emit({data:e,role:a});const u=t(o),p=o.leaveAnimation?o.leaveAnimation:n.get(s,"ios"===u?i:c);"gesture"!==a&&await E(o,p,o.el,d),o.didDismiss.emit({data:e,role:a}),r.delete(o)}catch(t){console.error(t)}return o.el.remove(),!0},B=t=>t.querySelector("ion-app")||t.body,E=async(t,o,e,a)=>{e.classList.remove("overlay-hidden");const s=o(e.shadowRoot||t.el,a);t.animated&&n.getBoolean("animated",!0)||s.duration(0),t.keyboardClose&&s.beforeAddWrite((()=>{const t=e.ownerDocument.activeElement;t&&t.matches("input, ion-input, ion-textarea")&&t.blur()}));const i=r.get(t)||[];return r.set(t,[...i,s]),await s.play(),!0},O=(t,n)=>{let o;const e=new Promise((t=>o=t));return P(t,n,(t=>{o(t.detail)})),e},P=(t,n,a)=>{const s=o=>{e(t,n,s),a(o)};o(t,n,s)},T=t=>"cancel"===t||t===I,z=t=>t(),G=(t,o)=>{if("function"==typeof t)return n.get("_zoneGate",z)((()=>{try{return t(o)}catch(t){console.error(t)}}))},I="backdrop";export{I as B,y as a,l as b,r as c,A as d,O as e,f,u as g,d as h,T as i,p as m,k as p,G as s,m as t}