import{g as L,p as x,j as D,aa as k,J as A,a4 as B,O as F,L as m,n as R,bv as g,ad as f,o as E,am as S,cc as T,d8 as I,R as h,d9 as y,ak as O}from"./index-DhxwW1_d.js";const K=x({fullscreen:Boolean,retainFocus:{type:Boolean,default:!0},scrollable:Boolean,...T({origin:"center center",scrollStrategy:"block",transition:{component:I},zIndex:2400})},"VDialog"),C=L()({name:"VDialog",props:K(),emits:{"update:modelValue":e=>!0,afterEnter:()=>!0,afterLeave:()=>!0},setup(e,V){let{emit:d,slots:v}=V;const r=D(e,"modelValue"),{scopeId:b}=k(),n=A();async function u(t){const a=t.relatedTarget,o=t.target;await h(),r.value&&a!==o&&n.value?.contentEl&&n.value?.globalTop&&![document,n.value.contentEl].includes(o)&&!n.value.contentEl.contains(o)&&y(n.value.contentEl)[0]?.focus()}function i(t){if(t.key!=="Tab"||!n.value?.contentEl)return;const a=y(n.value.contentEl);if(!a.length)return;const o=a[0],l=a[a.length-1],c=document.activeElement;t.shiftKey&&c===o?(t.preventDefault(),l.focus()):!t.shiftKey&&c===l&&(t.preventDefault(),o.focus())}B(()=>{document.removeEventListener("focusin",u),document.removeEventListener("keydown",i)}),F&&m(()=>r.value&&e.retainFocus,t=>{t?(document.addEventListener("focusin",u,{once:!0}),document.addEventListener("keydown",i)):(document.removeEventListener("focusin",u),document.removeEventListener("keydown",i))},{immediate:!0});function P(){d("afterEnter"),(e.scrim||e.retainFocus)&&n.value?.contentEl&&!n.value.contentEl.contains(document.activeElement)&&n.value.contentEl.focus({preventScroll:!0})}function w(){d("afterLeave")}return m(r,async t=>{t||(await h(),n.value.activatorEl?.focus({preventScroll:!0}))}),R(()=>{const t=g.filterProps(e),a=f({"aria-haspopup":"dialog"},e.activatorProps),o=f({tabindex:-1},e.contentProps);return E(g,f({ref:n,class:["v-dialog",{"v-dialog--fullscreen":e.fullscreen,"v-dialog--scrollable":e.scrollable},e.class],style:e.style},t,{modelValue:r.value,"onUpdate:modelValue":l=>r.value=l,"aria-modal":"true",activatorProps:a,contentProps:o,height:e.fullscreen?void 0:e.height,width:e.fullscreen?void 0:e.width,maxHeight:e.fullscreen?void 0:e.maxHeight,maxWidth:e.fullscreen?void 0:e.maxWidth,role:"dialog",onAfterEnter:P,onAfterLeave:w},b),{activator:v.activator,default:function(){for(var l=arguments.length,c=new Array(l),s=0;s<l;s++)c[s]=arguments[s];return E(O,{root:"VDialog"},{default:()=>[v.default?.(...c)]})}})}),S({},n)}});export{C as V};
