import{c as B}from"./f4OvDAmT.js";import{u as x}from"./COA9s1yS.js";import{P as G}from"./DT-hKSom.js";import{a as O,f as P,E as k,b as w}from"./BNOTwGsJ.js";import{u as M}from"./b1l8QPBl.js";import{d as N,C as V,r as c,c as A,o as D,w as g,f as $,u as i,D as U}from"./m2W8DxR4.js";const[W,j]=B("RovingFocusGroup");var K=N({__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(b,{expose:F,emit:I}){const a=b,f=I,{loop:S,orientation:p,dir:y}=V(a),v=x(y),l=M(a,"currentTabStopId",f,{defaultValue:a.defaultCurrentTabStopId,passive:a.currentTabStopId===void 0}),s=c(!1),n=c(!1),d=c(0),{getItems:m,CollectionSlot:C}=O({isProvider:!0});function T(e){const o=!n.value;if(e.currentTarget&&e.target===e.currentTarget&&o&&!s.value){const r=new CustomEvent(k,w);if(e.currentTarget.dispatchEvent(r),f("entryFocus",r),!r.defaultPrevented){const u=m().map(t=>t.ref).filter(t=>t.dataset.disabled!==""),R=u.find(t=>t.getAttribute("data-active")===""),_=u.find(t=>t.getAttribute("data-highlighted")===""),E=u.find(t=>t.id===l.value),q=[R,_,E,...u].filter(Boolean);P(q,a.preventScrollOnEntryFocus)}}n.value=!1}function h(){setTimeout(()=>{n.value=!1},1)}return F({getItems:m}),j({loop:S,dir:v,orientation:p,currentTabStopId:l,onItemFocus:e=>{l.value=e},onItemShiftTab:()=>{s.value=!0},onFocusableItemAdd:()=>{d.value++},onFocusableItemRemove:()=>{d.value--}}),(e,o)=>(D(),A(i(C),null,{default:g(()=>[$(i(G),{tabindex:s.value||d.value===0?-1:0,"data-orientation":i(p),as:e.as,"as-child":e.asChild,dir:i(v),style:{outline:"none"},onMousedown:o[0]||(o[0]=r=>n.value=!0),onMouseup:h,onFocus:T,onBlur:o[1]||(o[1]=r=>s.value=!1)},{default:g(()=>[U(e.$slots,"default")]),_:3},8,["tabindex","data-orientation","as","as-child","dir"])]),_:3}))}}),X=K;export{X as R,W as i};
