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