import{r as m,x as T,aA as B,cR as D,e as y,g as U,L as h,dI as C,B as $,dJ as k,dK as G,aE as R,a9 as L,a7 as K,ab as V,m as j,o as z,w as _,b as Y,n as S,ac as H,X as J}from"./BoB2h2qv.js";import{u as X}from"./CJyYPLmM.js";function M(){const e=m(),o=T(()=>["#text","#comment"].includes(e.value?.$el.nodeName)?e.value?.$el.nextElementSibling:B(e));return{primitiveElement:e,currentElement:o}}const x="data-reka-collection-item";function Q(e={}){const{key:o="",isProvider:l=!1}=e,t=`${o}CollectionProvider`;let r;if(l){const a=m(new Map);r={collectionRef:m(),itemMap:a},k(t,r)}else r=D(t);const w=(a=!1)=>{const n=r.collectionRef.value;if(!n)return[];const s=Array.from(n.querySelectorAll(`[${x}]`)),d=Array.from(r.itemMap.value.values()).sort((f,p)=>s.indexOf(f.ref)-s.indexOf(p.ref));return a?d:d.filter(f=>f.ref.dataset.disabled!=="")},A=y({name:"CollectionSlot",setup(a,{slots:n}){const{primitiveElement:s,currentElement:c}=M();return $(c,()=>{r.collectionRef.value=c.value}),()=>h(C,{ref:s},n)}}),F=y({name:"CollectionItem",inheritAttrs:!1,props:{value:{validator:()=>!0}},setup(a,{slots:n,attrs:s}){const{primitiveElement:c,currentElement:d}=M();return U(f=>{if(d.value){const p=G(d.value);r.itemMap.value.set(p,{ref:d.value,value:a.value}),f(()=>r.itemMap.value.delete(p))}}),()=>h(C,{...s,[x]:"",ref:c},n)}}),I=T(()=>Array.from(r.itemMap.value.values())),g=T(()=>r.itemMap.value.size);return{getItems:w,reactiveItems:I,itemMapSize:g,CollectionSlot:A,CollectionItem:F}}const W="rovingFocusGroup.onEntryFocus",Z={bubbles:!1,cancelable:!0},ee={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function te(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ie(e,o,l){const t=te(e.key,l);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(t))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(t)))return ee[t]}function oe(e,o=!1){const l=R();for(const t of e)if(t===l||(t.focus({preventScroll:o}),R()!==l))return}function le(e,o){return e.map((l,t)=>e[(o+t)%e.length])}const[ue,re]=V("RovingFocusGroup");var ne=y({__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:l}){const t=e,r=l,{loop:w,orientation:A,dir:F}=L(t),I=X(F),g=K(t,"currentTabStopId",r,{defaultValue:t.defaultCurrentTabStopId,passive:t.currentTabStopId===void 0}),a=m(!1),n=m(!1),s=m(0),{getItems:c,CollectionSlot:d}=Q({isProvider:!0});function f(i){const v=!n.value;if(i.currentTarget&&i.target===i.currentTarget&&v&&!a.value){const E=new CustomEvent(W,Z);if(i.currentTarget.dispatchEvent(E),r("entryFocus",E),!E.defaultPrevented){const b=c().map(u=>u.ref).filter(u=>u.dataset.disabled!==""),O=b.find(u=>u.getAttribute("data-active")===""),P=b.find(u=>u.getAttribute("data-highlighted")===""),N=b.find(u=>u.id===g.value),q=[O,P,N,...b].filter(Boolean);oe(q,t.preventScrollOnEntryFocus)}}n.value=!1}function p(){setTimeout(()=>{n.value=!1},1)}return o({getItems:c}),re({loop:w,dir:I,orientation:A,currentTabStopId:g,onItemFocus:i=>{g.value=i},onItemShiftTab:()=>{a.value=!0},onFocusableItemAdd:()=>{s.value++},onFocusableItemRemove:()=>{s.value--}}),(i,v)=>(z(),j(S(d),null,{default:_(()=>[Y(S(H),{tabindex:a.value||s.value===0?-1:0,"data-orientation":S(A),as:i.as,"as-child":i.asChild,dir:S(I),style:{outline:"none"},onMousedown:v[0]||(v[0]=E=>n.value=!0),onMouseup:p,onFocus:f,onBlur:v[1]||(v[1]=E=>a.value=!1)},{default:_(()=>[J(i.$slots,"default")]),_:3},8,["tabindex","data-orientation","as","as-child","dir"])]),_:3}))}}),ce=ne;export{ce as R,M as a,oe as f,ie as g,ue as i,Q as u,le as w};
