import{V as E,f as L,m as M,c as S,d as b}from"./forwardRefs-YZME3Z-4.js";import{s as O,x as K,J as U,z as B,W as H,c as V,r as N,V as z,D as F,I as W,Y as $,n as j,al as k,H as q,a5 as A,q as P,e as p,a7 as J,av as y,aw as Y,$ as G,ax as Q}from"./index-BrhME0Dw.js";import{u as X}from"./scopeId-Bb-xzR7W.js";import{f as Z}from"./index-W86lZ1ks.js";import{u as _}from"./dimensions-g-Hg75km.js";const ee=K({id:String,submenu:Boolean,...J(M({closeDelay:250,closeOnContentClick:!0,locationStrategy:"connected",location:void 0,openDelay:300,scrim:!1,scrollStrategy:"reposition",transition:{component:S}}),["absolute"])},"VMenu"),le=O()({name:"VMenu",props:ee(),emits:{"update:modelValue":a=>!0},setup(a,h){let{slots:c}=h;const s=U(a,"modelValue"),{scopeId:x}=X(),{isRtl:f}=B(),d=H(),m=V(()=>a.id||`v-menu-${d}`),o=N(),n=z(b,null),v=F(new Set);G(b,{register(){v.value.add(d)},unregister(){v.value.delete(d)},closeParents(e){setTimeout(()=>{var t;!v.value.size&&!a.persistent&&(e==null||(t=o.value)!=null&&t.contentEl&&!Q(e,o.value.contentEl))&&(s.value=!1,n==null||n.closeParents())},40)}}),W(()=>{n==null||n.unregister(),document.removeEventListener("focusin",g)}),$(()=>s.value=!1);async function g(e){var r,u,i;const t=e.relatedTarget,l=e.target;await j(),s.value&&t!==l&&((r=o.value)!=null&&r.contentEl)&&((u=o.value)!=null&&u.globalTop)&&![document,o.value.contentEl].includes(l)&&!o.value.contentEl.contains(l)&&((i=k(o.value.contentEl)[0])==null||i.focus())}q(s,e=>{e?(n==null||n.register(),A&&document.addEventListener("focusin",g,{once:!0})):(n==null||n.unregister(),A&&document.removeEventListener("focusin",g))},{immediate:!0});function D(e){n==null||n.closeParents(e)}function C(e){var t,l,r,u,i;if(!a.disabled)if(e.key==="Tab"||e.key==="Enter"&&!a.closeOnContentClick){if(e.key==="Enter"&&(e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLInputElement&&e.target.closest("form")))return;e.key==="Enter"&&e.preventDefault(),Y(k((t=o.value)==null?void 0:t.contentEl,!1),e.shiftKey?"prev":"next",I=>I.tabIndex>=0)||(s.value=!1,(r=(l=o.value)==null?void 0:l.activatorEl)==null||r.focus())}else a.submenu&&e.key===(f.value?"ArrowRight":"ArrowLeft")&&(s.value=!1,(i=(u=o.value)==null?void 0:u.activatorEl)==null||i.focus())}function w(e){var l;if(a.disabled)return;const t=(l=o.value)==null?void 0:l.contentEl;t&&s.value?e.key==="ArrowDown"?(e.preventDefault(),e.stopImmediatePropagation(),y(t,"next")):e.key==="ArrowUp"?(e.preventDefault(),e.stopImmediatePropagation(),y(t,"prev")):a.submenu&&(e.key===(f.value?"ArrowRight":"ArrowLeft")?s.value=!1:e.key===(f.value?"ArrowLeft":"ArrowRight")&&(e.preventDefault(),y(t,"first"))):(a.submenu?e.key===(f.value?"ArrowLeft":"ArrowRight"):["ArrowDown","ArrowUp"].includes(e.key))&&(s.value=!0,e.preventDefault(),setTimeout(()=>setTimeout(()=>w(e))))}const R=V(()=>P({"aria-haspopup":"menu","aria-expanded":String(s.value),"aria-controls":m.value,onKeydown:w},a.activatorProps));return _(()=>{const e=E.filterProps(a);return p(E,P({ref:o,id:m.value,class:["v-menu",a.class],style:a.style},e,{modelValue:s.value,"onUpdate:modelValue":t=>s.value=t,absolute:!0,activatorProps:R.value,location:a.location??(a.submenu?"end":"bottom"),"onClick:outside":D,onKeydown:C},x),{activator:c.activator,default:function(){for(var t=arguments.length,l=new Array(t),r=0;r<t;r++)l[r]=arguments[r];return p(Z,{root:"VMenu"},{default:()=>{var u;return[(u=c.default)==null?void 0:u.call(c,...l)]}})}})}),L({id:m,ΨopenChildren:v},o)}});export{le as V};
