import{z as x,bg as A,d as B,aj as O,ak as j,aZ as w,al as M,v,b2 as N,c as P,o as V,w as S,a as $,m as d,ai as D,ag as U}from"./Dk4AzF7j.js";import{j as z,E as K,k as Y}from"./D7D5X_-3.js";let m=0;function Q(){x(e=>{if(!A)return;const s=document.querySelectorAll("[data-reka-focus-guard]");document.body.insertAdjacentElement("afterbegin",s[0]??I()),document.body.insertAdjacentElement("beforeend",s[1]??I()),m++,e(()=>{m===1&&document.querySelectorAll("[data-reka-focus-guard]").forEach(c=>c.remove()),m--})})}function I(){const e=document.createElement("span");return e.setAttribute("data-reka-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}const[W,Z]=O("RovingFocusGroup");var H=B({__name:"RovingFocusGroup",props:{orientation:{type:String,required:!1,default:void 0},dir:{type:String,required:!1},loop:{type:Boolean,required:!1,default:!1},currentTabStopId:{type:[String,null],required:!1},defaultCurrentTabStopId:{type:String,required:!1},preventScrollOnEntryFocus:{type:Boolean,required:!1,default:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:["entryFocus","update:currentTabStopId"],setup(e,{expose:s,emit:c}){const n=e,g=c,{loop:C,orientation:b,dir:T}=j(n),y=w(T),f=M(n,"currentTabStopId",g,{defaultValue:n.defaultCurrentTabStopId,passive:n.currentTabStopId===void 0}),u=v(!1),i=v(!1),p=v(0),{getItems:F,CollectionSlot:E}=N({isProvider:!0});function h(t){const a=!i.value;if(t.currentTarget&&t.target===t.currentTarget&&a&&!u.value){const r=new CustomEvent(K,Y);if(t.currentTarget.dispatchEvent(r),g("entryFocus",r),!r.defaultPrevented){const l=F().map(o=>o.ref).filter(o=>o.dataset.disabled!==""),R=l.find(o=>o.getAttribute("data-active")===""),_=l.find(o=>o.getAttribute("data-highlighted")===""),k=l.find(o=>o.id===f.value),G=[R,_,k,...l].filter(Boolean);z(G,n.preventScrollOnEntryFocus)}}i.value=!1}function q(){setTimeout(()=>{i.value=!1},1)}return s({getItems:F}),Z({loop:C,dir:y,orientation:b,currentTabStopId:f,onItemFocus:t=>{f.value=t},onItemShiftTab:()=>{u.value=!0},onFocusableItemAdd:()=>{p.value++},onFocusableItemRemove:()=>{p.value--}}),(t,a)=>(V(),P(d(E),null,{default:S(()=>[$(d(D),{tabindex:u.value||p.value===0?-1:0,"data-orientation":d(b),as:t.as,"as-child":t.asChild,dir:d(y),style:{outline:"none"},onMousedown:a[0]||(a[0]=r=>i.value=!0),onMouseup:q,onFocus:h,onBlur:a[1]||(a[1]=r=>u.value=!1)},{default:S(()=>[U(t.$slots,"default")]),_:3},8,["tabindex","data-orientation","as","as-child","dir"])]),_:3}))}}),X=H;export{X as R,W as i,Q as u};
