"use strict";const Y=require("react"),d=require("./index-Dkj4QRX8.js"),D=require("./index-De-6atSi.js"),z=require("./index-1WIgmEZh.js"),V=require("./index-DO-atGp-.js"),G=require("./index-CDBBjNXc.js"),N=require("./index-ChLwd62c.js"),p=require("react/jsx-runtime");function J(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(o,r,t.get?t:{enumerable:!0,get:()=>e[r]})}}return o.default=e,Object.freeze(o)}const c=J(Y);var y="rovingFocusGroup.onEntryFocus",Q={bubbles:!1,cancelable:!0},b="RovingFocusGroup",[A,j,W]=D.createCollection(b),[X,Z]=V.createContextScope(b,[W]),[ee,te]=X(b),K=c.forwardRef((e,o)=>p.jsx(A.Provider,{scope:e.__scopeRovingFocusGroup,children:p.jsx(A.Slot,{scope:e.__scopeRovingFocusGroup,children:p.jsx(oe,{...e,ref:o})})}));K.displayName=b;var oe=c.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:r,orientation:t,loop:S=!1,dir:T,currentTabStopId:v,defaultCurrentTabStopId:w,onCurrentTabStopIdChange:C,onEntryFocus:m,preventScrollOnEntryFocus:u=!1,...I}=e,g=c.useRef(null),F=z.useComposedRefs(o,g),R=D.useDirection(T),[E,n]=d.useControllableState({prop:v,defaultProp:w??null,onChange:C,caller:b}),[i,x]=c.useState(!1),a=G.useCallbackRef(m),l=j(r),_=c.useRef(!1),[L,O]=c.useState(0);return c.useEffect(()=>{const s=g.current;if(s)return s.addEventListener(y,a),()=>s.removeEventListener(y,a)},[a]),p.jsx(ee,{scope:r,orientation:t,dir:R,loop:S,currentTabStopId:E,onItemFocus:c.useCallback(s=>n(s),[n]),onItemShiftTab:c.useCallback(()=>x(!0),[]),onFocusableItemAdd:c.useCallback(()=>O(s=>s+1),[]),onFocusableItemRemove:c.useCallback(()=>O(s=>s-1),[]),children:p.jsx(N.Primitive.div,{tabIndex:i||L===0?-1:0,"data-orientation":t,...I,ref:F,style:{outline:"none",...e.style},onMouseDown:d.composeEventHandlers(e.onMouseDown,()=>{_.current=!0}),onFocus:d.composeEventHandlers(e.onFocus,s=>{const U=!_.current;if(s.target===s.currentTarget&&U&&!i){const P=new CustomEvent(y,Q);if(s.currentTarget.dispatchEvent(P),!P.defaultPrevented){const h=l().filter(f=>f.focusable),H=h.find(f=>f.active),B=h.find(f=>f.id===E),$=[H,B,...h].filter(Boolean).map(f=>f.ref.current);q($,u)}}_.current=!1}),onBlur:d.composeEventHandlers(e.onBlur,()=>x(!1))})})}),M="RovingFocusGroupItem",k=c.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:r,focusable:t=!0,active:S=!1,tabStopId:T,children:v,...w}=e,C=G.useId(),m=T||C,u=te(M,r),I=u.currentTabStopId===m,g=j(r),{onFocusableItemAdd:F,onFocusableItemRemove:R,currentTabStopId:E}=u;return c.useEffect(()=>{if(t)return F(),()=>R()},[t,F,R]),p.jsx(A.ItemSlot,{scope:r,id:m,focusable:t,active:S,children:p.jsx(N.Primitive.span,{tabIndex:I?0:-1,"data-orientation":u.orientation,...w,ref:o,onMouseDown:d.composeEventHandlers(e.onMouseDown,n=>{t?u.onItemFocus(m):n.preventDefault()}),onFocus:d.composeEventHandlers(e.onFocus,()=>u.onItemFocus(m)),onKeyDown:d.composeEventHandlers(e.onKeyDown,n=>{if(n.key==="Tab"&&n.shiftKey){u.onItemShiftTab();return}if(n.target!==n.currentTarget)return;const i=se(n,u.orientation,u.dir);if(i!==void 0){if(n.metaKey||n.ctrlKey||n.altKey||n.shiftKey)return;n.preventDefault();let a=g().filter(l=>l.focusable).map(l=>l.ref.current);if(i==="last")a.reverse();else if(i==="prev"||i==="next"){i==="prev"&&a.reverse();const l=a.indexOf(n.currentTarget);a=u.loop?ce(a,l+1):a.slice(l+1)}setTimeout(()=>q(a))}}),children:typeof v=="function"?v({isCurrentTabStop:I,hasTabStop:E!=null}):v})})});k.displayName=M;var re={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ne(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function se(e,o,r){const t=ne(e.key,r);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(t))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(t)))return re[t]}function q(e,o=!1){const r=document.activeElement;for(const t of e)if(t===r||(t.focus({preventScroll:o}),document.activeElement!==r))return}function ce(e,o){return e.map((r,t)=>e[(o+t)%e.length])}var ue=K,ae=k;exports.Item=ae;exports.Root=ue;exports.createRovingFocusGroupScope=Z;
//# sourceMappingURL=index-CyMbLkj0.js.map
