import{z as x,be as A,d as B,ah as O,ai as j,aX as w,aj as M,v,b0 as N,c as P,o as V,w as S,a as $,m as d,ag as D,ae as U}from"./B08CJtNn.js";import{j as z,E as K,k as X}from"./BTwP6ady.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,Y]=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:h}=N({isProvider:!0});function E(t){const a=!i.value;if(t.currentTarget&&t.target===t.currentTarget&&a&&!u.value){const r=new CustomEvent(K,X);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")===""),G=l.find(o=>o.id===f.value),k=[R,_,G,...l].filter(Boolean);z(k,n.preventScrollOnEntryFocus)}}i.value=!1}function q(){setTimeout(()=>{i.value=!1},1)}return s({getItems:F}),Y({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(h),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:E,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}))}}),Z=H;export{Z as R,W as i,Q as u};
