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