import{a as n,U as t,V as e}from"./p-DGWPFpP6.js";const o='[tabindex]:not([tabindex^="-"]):not([hidden]):not([disabled]), input:not([type=hidden]):not([tabindex^="-"]):not([hidden]):not([disabled]), textarea:not([tabindex^="-"]):not([hidden]):not([disabled]), button:not([tabindex^="-"]):not([hidden]):not([disabled]), select:not([tabindex^="-"]):not([hidden]):not([disabled]), .bal-focusable:not([tabindex^="-"]):not([hidden]):not([disabled]), .bal-focusable[disabled="false"]:not([tabindex^="-"]):not([hidden])',a=(n,t)=>{const e=n.querySelector(o);l(e,null!=t?t:n)},d=(n,t)=>{const e=Array.from(n.querySelectorAll(o));l(e.length>0?e[e.length-1]:null,null!=t?t:n)},l=(n,t)=>{let e=n;const a=null==n?void 0:n.shadowRoot;a&&(e=a.querySelector(o)||n),e?s(e):t.focus({preventScroll:!0})},s=n=>{if(n.focus({preventScroll:!0}),n.classList.contains("bal-focusable")){const t=n.closest("bal-app");t&&t.setFocus([n])}};let i=0;const r=t=>{n.hasDocument&&u(document);const e=i++;t.overlayIndex=e,t.el.hasAttribute("id")||(t.el.id=`bal-overlay-${e}`)},b=(n,t)=>(void 0===t&&(t="bal-modal,bal-snackbar,bal-toast"),Array.from(n.querySelectorAll(t)).filter((n=>n.overlayIndex>0))),c=(n,t,e)=>{const o=b(n,t);return void 0===e?o[o.length-1]:o.find((n=>n.id===e))},u=n=>{0===i&&(i=1,n.addEventListener("focus",(t=>{p(t,n)}),!0),n.addEventListener("keyup",(t=>{if("Escape"===t.key){const t=c(n);if(t){if(!1===t.isClosable)return;t.dismiss(void 0,"backdrop")}}})))},f=n=>n.classList.contains("is-hidden"),p=(n,t)=>{const e=(n=>{const t=((n,t)=>b(n,t).filter((n=>!f(n))))(n,"bal-modal");return t[t.length-1]})(t),o=n.target;e&&o&&(e.shadowRoot?(()=>{if(e.contains(o))e.lastFocus=o;else if("BAL-TOAST"===o.tagName)m(e.lastFocus,e);else{const n=e.lastFocus;a(e),n===t.activeElement&&d(e),e.lastFocus=t.activeElement}})():(()=>{if(e===o)e.lastFocus=void 0;else{const n=e,l=n.querySelector(".bal-modal__container");if(!l)return;if(l.contains(o)||o===n.querySelector("bal-modal__background"))e.lastFocus=o;else{const n=e.lastFocus;a(l,e),n===t.activeElement&&d(l,e),e.lastFocus=t.activeElement}}})())},h=async(n,t,e,o)=>{if(!n.presented)return!1;try{n.el.style.setProperty("pointer-events","none"),n.willDismiss.emit({data:t,role:e}),await o(),n.presented=!1,n.didDismiss.emit({data:t,role:e})}catch(t){n.presented=!1,console.error(t)}return n.el.remove(),!0},v=(n,t)=>{let e;const o=new Promise((n=>e=n));return x(n,t,(n=>{e(n.detail)})),o},x=(n,o,a)=>{const d=t=>{e(n,o,d),a(t)};t(n,o,d)},m=(n,t)=>{let e=n;const a=null==n?void 0:n.shadowRoot;a&&(e=a.querySelector(o)||n),e?s(e):t.focus()},y="bal-disable-focus-trap";export{y as F,c as a,h as d,v as e,b as g,r as p}