import{ba as w,ac as O,h as x,b0 as q,ag as B,E as v,v as P,o as U,w as I,b as D,g as d,ae as G,x as N}from"./BzhixHsn.js";import{u as L,f as M}from"./Bp3-KBkO.js";const V="rovingFocusGroup.onEntryFocus",k={bubbles:!1,cancelable:!0},K={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Y(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Q(e,o,a){const t=Y(e.key,a);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(t))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(t)))return K[t]}function $(e,o=!1){const a=w();for(const t of e)if(t===a||(t.focus({preventScroll:o}),w()!==a))return}function W(e,o){return e.map((a,t)=>e[(o+t)%e.length])}const[X,j]=O("RovingFocusGroup");var z=x({__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:o,emit:a}){const t=e,g=a,{loop:S,orientation:m,dir:T}=q(t),b=L(T),f=B(t,"currentTabStopId",g,{defaultValue:t.defaultCurrentTabStopId,passive:t.currentTabStopId===void 0}),i=v(!1),l=v(!1),p=v(0),{getItems:F,CollectionSlot:h}=M({isProvider:!0});function A(r){const s=!l.value;if(r.currentTarget&&r.target===r.currentTarget&&s&&!i.value){const u=new CustomEvent(V,k);if(r.currentTarget.dispatchEvent(u),g("entryFocus",u),!u.defaultPrevented){const c=F().map(n=>n.ref).filter(n=>n.dataset.disabled!==""),C=c.find(n=>n.getAttribute("data-active")===""),_=c.find(n=>n.getAttribute("data-highlighted")===""),y=c.find(n=>n.id===f.value),R=[C,_,y,...c].filter(Boolean);$(R,t.preventScrollOnEntryFocus)}}l.value=!1}function E(){setTimeout(()=>{l.value=!1},1)}return o({getItems:F}),j({loop:S,dir:b,orientation:m,currentTabStopId:f,onItemFocus:r=>{f.value=r},onItemShiftTab:()=>{i.value=!0},onFocusableItemAdd:()=>{p.value++},onFocusableItemRemove:()=>{p.value--}}),(r,s)=>(U(),P(d(h),null,{default:I(()=>[D(d(G),{tabindex:i.value||p.value===0?-1:0,"data-orientation":d(m),as:r.as,"as-child":r.asChild,dir:d(b),style:{outline:"none"},onMousedown:s[0]||(s[0]=u=>l.value=!0),onMouseup:E,onFocus:A,onBlur:s[1]||(s[1]=u=>i.value=!1)},{default:I(()=>[N(r.$slots,"default")]),_:3},8,["tabindex","data-orientation","as","as-child","dir"])]),_:3}))}}),Z=z;export{Z as R,$ as f,Q as g,X as i,W as w};
