import{g as t,c as n}from"./p-202e7480.js";import{OVERLAY_BACK_BUTTON_PRIORITY as o}from"./p-f2660943.js";import{c as e,a,r as i,g as s}from"./p-5a5a5c96.js";let r=0;const c=new WeakMap,d=t=>({create:n=>b(t,n),dismiss:(n,o,e)=>g(document,n,o,t,e),getTop:async()=>k(document,t)}),u=d("ion-alert"),p=d("ion-action-sheet"),l=d("ion-loading"),m=d("ion-modal"),f=d("ion-picker"),y=d("ion-popover"),v=t=>{"undefined"!=typeof document&&w(document);const n=r++;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),E(document).appendChild(o),new Promise((t=>e(o,t)))})):Promise.resolve(),x='[tabindex]:not([tabindex^="-"]), input:not([type=hidden]):not([tabindex^="-"]), textarea:not([tabindex^="-"]), button:not([tabindex^="-"]), select:not([tabindex^="-"]), .ion-focusable:not([tabindex^="-"])',h="input:not([type=hidden]), textarea, button, select",w=t=>{0===r&&(r=1,t.addEventListener("focus",(n=>((t,n)=>{const o=k(n),e=t.target;if(o&&e)if(o===e)o.lastFocus=void 0;else{const t=s(o);if(!t.contains(e))return;const a=t.querySelector(".ion-overlay-wrapper");if(!a)return;if(a.contains(e))o.lastFocus=e;else{const t=o.lastFocus;((t,n)=>{let o=t.querySelector(x);const e=o&&o.shadowRoot;e&&(o=e.querySelector(h)||o),o?o.focus():n.focus()})(a,o),t===n.activeElement&&((t,n)=>{const o=Array.from(t.querySelectorAll(x));let e=o.length>0?o[o.length-1]:null;const a=e&&e.shadowRoot;a&&(e=a.querySelector(h)||e),e?e.focus():n.focus()})(a,o),o.lastFocus=n.activeElement}}})(n,t)),!0),t.addEventListener("ionBackButton",(n=>{const e=k(t);e&&e.backdropDismiss&&n.detail.register(o,(()=>e.dismiss(void 0,N)))})),t.addEventListener("keyup",(n=>{if("Escape"===n.key){const n=k(t);n&&n.backdropDismiss&&n.dismiss(void 0,N)}})))},g=(t,n,o,e,a)=>{const i=k(t,e,a);return i?i.dismiss(n,o):Promise.reject("overlay does not exist")},k=(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))},j=(t=!1)=>{const n=E(document).querySelector("ion-router-outlet, ion-nav, #ion-view-container-root");n&&(t?n.setAttribute("aria-hidden","true"):n.removeAttribute("aria-hidden"))},P=async(o,e,a,i,s)=>{if(o.presented)return;j(!0),o.presented=!0,o.willPresent.emit();const r=t(o),c=o.enterAnimation?o.enterAnimation:n.get(e,"ios"===r?a:i);await O(o,c,o.el,s)&&o.didPresent.emit(),"ION-TOAST"!==o.el.tagName&&A(o.el),o.keyboardClose&&o.el.focus()},A=async t=>{let n=document.activeElement;if(!n)return;const o=n&&n.shadowRoot;o&&(n=o.querySelector(h)||n),await t.onDidDismiss(),n.focus()},B=async(o,e,a,i,s,r,d)=>{if(!o.presented)return!1;j(!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(i,"ios"===u?s:r);"gesture"!==a&&await O(o,p,o.el,d),o.didDismiss.emit({data:e,role:a}),c.delete(o)}catch(t){console.error(t)}return o.el.remove(),!0},E=t=>t.querySelector("ion-app")||t.body,O=async(t,o,e,a)=>{e.classList.remove("overlay-hidden");const i=o(e.shadowRoot||t.el,a);t.animated&&n.getBoolean("animated",!0)||i.duration(0),t.keyboardClose&&i.beforeAddWrite((()=>{const t=e.ownerDocument.activeElement;t&&t.matches("input, ion-input, ion-textarea")&&t.blur()}));const s=c.get(t)||[];return c.set(t,[...s,i]),await i.play(),!0},T=(t,n)=>{let o;const e=new Promise((t=>o=t));return z(t,n,(t=>{o(t.detail)})),e},z=(t,n,o)=>{const e=a=>{i(t,n,e),o(a)};a(t,n,e)},G=t=>"cancel"===t||t===N,I=t=>t(),M=(t,o)=>{if("function"==typeof t)return n.get("_zoneGate",I)((()=>{try{return t(o)}catch(t){console.error(t)}}))},N="backdrop";export{N as B,u as a,v as b,f as c,B as d,T as e,c as f,y as g,p as h,G as i,l,m,P as p,M as s}