/*!
 * (C) Ionic http://ionicframework.com - MIT License
 */
import{b as t}from"./p-246d420d.js";import{g as n}from"./p-aa100da7.js";import{OVERLAY_BACK_BUTTON_PRIORITY as o}from"./p-0b7fe16d.js";import{c as e,a,b as i,g as s}from"./p-1373e401.js";let r=0;const c=new WeakMap,d=t=>({create:n=>x(t,n),dismiss:(n,o,e)=>k(document,n,o,t,e),getTop:async()=>j(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"),b=d("ion-toast"),v=t=>{"undefined"!=typeof document&&g(document);const n=r++;t.overlayIndex=n,t.hasAttribute("id")||(t.id=`ion-overlay-${n}`)},x=(t,n)=>"undefined"!=typeof customElements?customElements.whenDefined(t).then((()=>{const o=document.createElement(t);return o.classList.add("overlay-hidden"),Object.assign(o,n),P(document).appendChild(o),new Promise((t=>e(o,t)))})):Promise.resolve(),h='[tabindex]:not([tabindex^="-"]), input:not([type=hidden]):not([tabindex^="-"]), textarea:not([tabindex^="-"]), button:not([tabindex^="-"]), select:not([tabindex^="-"]), .ion-focusable:not([tabindex^="-"])',w="input:not([type=hidden]), textarea, button, select",g=t=>{0===r&&(r=1,t.addEventListener("focus",(n=>((t,n)=>{const o=j(n),e=t.target;if(o&&e&&!o.notTrapFocus)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(h);const e=o&&o.shadowRoot;e&&(o=e.querySelector(w)||o),o?o.focus():n.focus()})(a,o),t===n.activeElement&&((t,n)=>{const o=Array.from(t.querySelectorAll(h));let e=o.length>0?o[o.length-1]:null;const a=e&&e.shadowRoot;a&&(e=a.querySelector(w)||e),e?e.focus():n.focus()})(a,o),o.lastFocus=n.activeElement}}})(n,t)),!0),t.addEventListener("ionBackButton",(n=>{const e=j(t);e&&e.backdropDismiss&&n.detail.register(o,(()=>e.dismiss(void 0,G)))})),t.addEventListener("keyup",(n=>{if("Escape"===n.key){const n=j(t);n&&n.backdropDismiss&&n.dismiss(void 0,G)}})))},k=(t,n,o,e,a)=>{const i=j(t,e,a);return i?i.dismiss(n,o):Promise.reject("overlay does not exist")},j=(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))},E=(t=!1)=>{const n=P(document).querySelector("ion-router-outlet, ion-nav, #ion-view-container-root");n&&(t?n.setAttribute("aria-hidden","true"):n.removeAttribute("aria-hidden"))},O=async(o,e,a,i,s)=>{if(o.presented)return;E(!0),o.presented=!0,o.willPresent.emit();const r=n(o),c=o.enterAnimation?o.enterAnimation:t.get(e,"ios"===r?a:i);await B(o,c,o.el,s)&&o.didPresent.emit(),"ION-TOAST"===o.el.tagName||"ION-ACTION-SHEET"===o.el.tagName||o.el.notTrapFocus||T(o.el),o.keyboardClose&&o.el.focus()},T=async t=>{let n=document.activeElement;if(!n)return;const o=n&&n.shadowRoot;o&&(n=o.querySelector(w)||n),await t.onDidDismiss(),n.focus()},A=async(o,e,a,i,s,r,d)=>{if(!o.presented)return!1;E(!1),o.presented=!1;try{o.el.style.setProperty("pointer-events","none"),o.willDismiss.emit({data:e,role:a});const u=n(o),p=o.leaveAnimation?o.leaveAnimation:t.get(i,"ios"===u?s:r);"gesture"!==a&&await B(o,p,o.el,d),o.didDismiss.emit({data:e,role:a}),c.delete(o)}catch(u){console.error(u)}return o.el.remove(),!0},P=t=>t.querySelector("ion-app")||t.body,B=async(n,o,e,a)=>{e.classList.remove("overlay-hidden");const i=o(e.shadowRoot||n.el,a);n.animated&&t.getBoolean("animated",!0)||i.duration(0),n.keyboardClose&&i.beforeAddWrite((()=>{const t=e.ownerDocument.activeElement;t&&t.matches("input, ion-input, ion-textarea")&&t.blur()}));const s=c.get(n)||[];return c.set(n,[...s,i]),await i.play(),!0},I=(t,n)=>{let o;const e=new Promise((t=>o=t));return N(t,n,(t=>{o(t.detail)})),e},N=(t,n,o)=>{const e=a=>{i(t,n,e),o(a)};a(t,n,e)},S=t=>"cancel"===t||t===G,z=t=>t(),C=(n,o)=>{if("function"==typeof n)return t.get("_zoneGate",z)((()=>{try{return n(o)}catch(t){console.error(t)}}))},G="backdrop";export{G as B,u as a,p as b,y as c,O as d,v as e,A as f,I as g,c as h,S as i,l,m,f as p,C as s,b as t}