import{u as y,m as w,V as v}from"./VOverlay-DlJb3QlW.js";import{f as D}from"./forwardRefs-CB8NoG9r.js";import{g as L,p as A,ai as B,r as F,e as S,az as I,w as g,u as O,by as R,O as d,c as E,ah as T,a2 as W}from"./index-C5GbdPxY.js";import{a as z}from"./VMenu-CT0Fri-T.js";const C=A({fullscreen:Boolean,retainFocus:{type:Boolean,default:!0},scrollable:Boolean,...w({origin:"center center",scrollStrategy:"block",transition:{component:z},zIndex:2400})},"VDialog"),M=L()({name:"VDialog",props:C(),emits:{"update:modelValue":e=>!0,afterEnter:()=>!0,afterLeave:()=>!0},setup(e,h){let{emit:m,slots:s}=h;const u=B(e,"modelValue"),{scopeId:V}=y(),t=F();function f(a){var l,c;const o=a.relatedTarget,r=a.target;if(o!==r&&((l=t.value)!=null&&l.contentEl)&&((c=t.value)!=null&&c.globalTop)&&![document,t.value.contentEl].includes(r)&&!t.value.contentEl.contains(r)){const n=R(t.value.contentEl);if(!n.length)return;const i=n[0],x=n[n.length-1];o===i?x.focus():i.focus()}}S(()=>{document.removeEventListener("focusin",f)}),I&&g(()=>u.value&&e.retainFocus,a=>{a?document.addEventListener("focusin",f):document.removeEventListener("focusin",f)},{immediate:!0});function P(){var a;m("afterEnter"),(e.scrim||e.retainFocus)&&((a=t.value)!=null&&a.contentEl)&&!t.value.contentEl.contains(document.activeElement)&&t.value.contentEl.focus({preventScroll:!0})}function b(){m("afterLeave")}return g(u,async a=>{var o;a||(await W(),(o=t.value.activatorEl)==null||o.focus({preventScroll:!0}))}),O(()=>{const a=v.filterProps(e),o=d({"aria-haspopup":"dialog"},e.activatorProps),r=d({tabindex:-1},e.contentProps);return E(v,d({ref:t,class:["v-dialog",{"v-dialog--fullscreen":e.fullscreen,"v-dialog--scrollable":e.scrollable},e.class],style:e.style},a,{modelValue:u.value,"onUpdate:modelValue":l=>u.value=l,"aria-modal":"true",activatorProps:o,contentProps:r,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:b},V),{activator:s.activator,default:function(){for(var l=arguments.length,c=new Array(l),n=0;n<l;n++)c[n]=arguments[n];return E(T,{root:"VDialog"},{default:()=>{var i;return[(i=s.default)==null?void 0:i.call(s,...c)]}})}})}),D({},t)}});export{M as V};
