import{o as m,G as M,e as u,d as O,j as x,r as l,k as K,z as $,L as A,ah as F,f as s,P,ag as V,c as G,O as f,n as R,C as B,a6 as U,aW as j,az as H,aX as W}from"./llFuKhWI.js";import{g as X}from"./DAdDEog1.js";import{T as Y}from"./C-7E03RX.js";const q={xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16"},J=u("path",{fill:"currentColor",d:"M11.146 4.146a.5.5 0 0 1 .708.708L8.707 8l3.147 3.146a.5.5 0 0 1-.708.708L8 8.707l-3.146 3.147a.5.5 0 0 1-.708-.708L7.293 8 4.146 4.854a.5.5 0 1 1 .708-.708L8 7.293z"},null,-1),Q=[J];function Z(p,v){return m(),M("svg",q,[...Q])}const ee={render:Z},oe=["data-testid"],ae={"aria-hidden":"true"},te=30,L="Tab",ue=O({__name:"Modal",props:{open:{type:Boolean,default:!1},noPadding:{type:Boolean,default:!1},modalName:{default:""},classes:{default:()=>({})},noCloseButton:{type:Boolean,default:!1}},emits:["closed"],setup(p,{expose:v,emit:g}){const _=x("openModals",()=>new Map),C={modal:"",backdrop:""},S=g,t=p,{freezeScroll:D,unfreezeScroll:N}=W(),h=l(!1),n=l(t.open),c=l(!1),i=l(),a=l([]),k=K(()=>({...C,...t.classes}));function z(){_.value.set(t.modalName,!0),n.value=!0,r(!1),H(()=>{I()})}function d(){c.value=!0,r(!0),setTimeout(()=>{_.value.delete(t.modalName),n.value=!1,c.value=!1,y(),S("closed")},350)}function I(){setTimeout(()=>{var e,o,b;i.value&&(a.value=X({parent:i.value}),(e=a.value[0])==null||e.focus(),(o=a.value[a.value.length-1])==null||o.addEventListener("keydown",E),(b=a.value[0])==null||b.addEventListener("keydown",T))},te)}function y(){var e,o;(e=a.value[a.value.length-1])==null||e.removeEventListener("keydown",E),(o=a.value[0])==null||o.removeEventListener("keydown",T)}function r(e){e?N():D()}function w(e){n.value&&e.key==="Escape"&&d()}function E(e){var o;e.key===L&&!e.shiftKey&&(e.preventDefault(),(o=a.value[0])==null||o.focus())}function T(e){var o;e.key===L&&e.shiftKey&&(e.preventDefault(),(o=a.value[a.value.length-1])==null||o.focus())}return $(()=>t.open,e=>{n.value=e,r(!e)}),A(()=>{window.addEventListener("keyup",w),h.value=!0}),F(()=>{r(!0),window.removeEventListener("keyup",w),y()}),v({openModal:z,closeModal:d,isOpen:n}),(e,o)=>s(h)?P((m(),G(j,{key:0,to:"body"},[u("div",{ref_key:"refModal",ref:i,class:f([[{"is-open":s(n),"is-fading-out":s(c)},`modal-${t.modalName}`],"modal"]),"data-testid":("TESTID"in e?e.TESTID:s(Y)).MODAL.DIALOG},[u("div",{class:f([s(k).backdrop,"modal__backdrop"]),"aria-hidden":"true",onClick:d},null,2),u("div",{class:f([[s(k).modal,{"p-0":t.noPadding}],"modal__content"])},[t.noCloseButton?B("",!0):(m(),M("button",{key:0,ref:"closeButton","aria-label":"Close Modal",class:"button is-white modal__close",type:"button",onClick:d},[u("span",ae,[R(s(ee),{class:"tw-inline"})])],512)),U(e.$slots,"default")],2)],10,oe)],512)),[[V,s(n)]]):B("",!0)}});export{ue as _};