import{a as M,b as L}from"/build/_shared/chunk-IXWAFOW5.js";import{a as b,c as G,e as P,f as O,g as N,h as T}from"/build/_shared/chunk-7Z6LVCRT.js";import{p as I,r as D}from"/build/_shared/chunk-VX2L2R2M.js";import{a as q}from"/build/_shared/chunk-XIQ3C74K.js";import{d as z}from"/build/_shared/chunk-G5WX4PPA.js";var o=z(q(),1);var w="rovingFocusGroup.onEntryFocus",J={bubbles:!1,cancelable:!0},A="RovingFocusGroup",[_,U,Q]=M(A),[W,Fe]=G(A,[Q]),[X,Z]=W(A),ee=(0,o.forwardRef)((e,t)=>(0,o.createElement)(_.Provider,{scope:e.__scopeRovingFocusGroup},(0,o.createElement)(_.Slot,{scope:e.__scopeRovingFocusGroup},(0,o.createElement)(oe,I({},e,{ref:t}))))),oe=(0,o.forwardRef)((e,t)=>{let{__scopeRovingFocusGroup:s,orientation:r,loop:v=!1,dir:F,currentTabStopId:g,defaultCurrentTabStopId:R,onCurrentTabStopIdChange:l,onEntryFocus:a,...C}=e,$=(0,o.useRef)(null),m=D(t,$),p=L(F),[c=null,d]=N({prop:g,defaultProp:R,onChange:l}),[E,f]=(0,o.useState)(!1),u=O(a),K=U(s),S=(0,o.useRef)(!1),[B,x]=(0,o.useState)(0);return(0,o.useEffect)(()=>{let n=$.current;if(n)return n.addEventListener(w,u),()=>n.removeEventListener(w,u)},[u]),(0,o.createElement)(X,{scope:s,orientation:r,dir:p,loop:v,currentTabStopId:c,onItemFocus:(0,o.useCallback)(n=>d(n),[d]),onItemShiftTab:(0,o.useCallback)(()=>f(!0),[]),onFocusableItemAdd:(0,o.useCallback)(()=>x(n=>n+1),[]),onFocusableItemRemove:(0,o.useCallback)(()=>x(n=>n-1),[])},(0,o.createElement)(T.div,I({tabIndex:E||B===0?-1:0,"data-orientation":r},C,{ref:m,style:{outline:"none",...e.style},onMouseDown:b(e.onMouseDown,()=>{S.current=!0}),onFocus:b(e.onFocus,n=>{let H=!S.current;if(n.target===n.currentTarget&&H&&!E){let h=new CustomEvent(w,J);if(n.currentTarget.dispatchEvent(h),!h.defaultPrevented){let y=K().filter(i=>i.focusable),Y=y.find(i=>i.active),j=y.find(i=>i.id===c),V=[Y,j,...y].filter(Boolean).map(i=>i.ref.current);k(V)}}S.current=!1}),onBlur:b(e.onBlur,()=>f(!1))})))}),te="RovingFocusGroupItem",re=(0,o.forwardRef)((e,t)=>{let{__scopeRovingFocusGroup:s,focusable:r=!0,active:v=!1,tabStopId:F,...g}=e,R=P(),l=F||R,a=Z(te,s),C=a.currentTabStopId===l,$=U(s),{onFocusableItemAdd:m,onFocusableItemRemove:p}=a;return(0,o.useEffect)(()=>{if(r)return m(),()=>p()},[r,m,p]),(0,o.createElement)(_.ItemSlot,{scope:s,id:l,focusable:r,active:v},(0,o.createElement)(T.span,I({tabIndex:C?0:-1,"data-orientation":a.orientation},g,{ref:t,onMouseDown:b(e.onMouseDown,c=>{r?a.onItemFocus(l):c.preventDefault()}),onFocus:b(e.onFocus,()=>a.onItemFocus(l)),onKeyDown:b(e.onKeyDown,c=>{if(c.key==="Tab"&&c.shiftKey){a.onItemShiftTab();return}if(c.target!==c.currentTarget)return;let d=ce(c,a.orientation,a.dir);if(d!==void 0){c.preventDefault();let f=$().filter(u=>u.focusable).map(u=>u.ref.current);if(d==="last")f.reverse();else if(d==="prev"||d==="next"){d==="prev"&&f.reverse();let u=f.indexOf(c.currentTarget);f=a.loop?ae(f,u+1):f.slice(u+1)}setTimeout(()=>k(f))}})})))}),ne={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function se(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ce(e,t,s){let r=se(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ne[r]}function k(e){let t=document.activeElement;for(let s of e)if(s===t||(s.focus(),document.activeElement!==t))return}function ae(e,t){return e.map((s,r)=>e[(t+r)%e.length])}var ge=ee,Re=re;export{Fe as a,ge as b,Re as c};
