import{R as g,a as b,r as a}from"./app-6e13b0c9.js";import{c as G,u as q,b as $,a as h,d as J,e as Q}from"./index-7f804fb5.js";import{u as M,a as D}from"./index-79a730ad.js";import{P as L}from"./index-1a7315b2.js";function X(e){const o=e+"CollectionProvider",[s,r]=G(o),[R,p]=s(o,{collectionRef:{current:null},itemMap:new Map}),v=d=>{const{scope:t,children:u}=d,m=g.useRef(null),n=g.useRef(new Map).current;return b(R,{scope:t,itemMap:n,collectionRef:m,children:u})};v.displayName=o;const I=e+"CollectionSlot",l=g.forwardRef((d,t)=>{const{scope:u,children:m}=d,n=p(I,u),i=M(t,n.collectionRef);return b(D,{ref:i,children:m})});l.displayName=I;const c=e+"CollectionItemSlot",E="data-radix-collection-item",F=g.forwardRef((d,t)=>{const{scope:u,children:m,...n}=d,i=g.useRef(null),w=M(t,i),T=p(c,u);return g.useEffect(()=>(T.itemMap.set(i,{ref:i,...n}),()=>void T.itemMap.delete(i))),b(D,{[E]:"",ref:w,children:m})});F.displayName=c;function C(d){const t=p(e+"CollectionConsumer",d);return g.useCallback(()=>{const m=t.collectionRef.current;if(!m)return[];const n=Array.from(m.querySelectorAll(`[${E}]`));return Array.from(t.itemMap.values()).sort((T,A)=>n.indexOf(T.ref.current)-n.indexOf(A.ref.current))},[t.collectionRef,t.itemMap])}return[{Provider:v,Slot:l,ItemSlot:F},C,r]}var Z=a.createContext(void 0);function ee(e){const o=a.useContext(Z);return e||o||"ltr"}var _="rovingFocusGroup.onEntryFocus",te={bubbles:!1,cancelable:!0},y="RovingFocusGroup",[N,z,oe]=X(y),[re,Ie]=G(y,[oe]),[ne,se]=re(y),k=a.forwardRef((e,o)=>b(N.Provider,{scope:e.__scopeRovingFocusGroup,children:b(N.Slot,{scope:e.__scopeRovingFocusGroup,children:b(ce,{...e,ref:o})})}));k.displayName=y;var ce=a.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:s,orientation:r,loop:R=!1,dir:p,currentTabStopId:v,defaultCurrentTabStopId:I,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:E=!1,...F}=e,C=a.useRef(null),d=M(o,C),t=ee(p),[u=null,m]=q({prop:v,defaultProp:I,onChange:l}),[n,i]=a.useState(!1),w=$(c),T=z(s),A=a.useRef(!1),[H,O]=a.useState(0);return a.useEffect(()=>{const f=C.current;if(f)return f.addEventListener(_,w),()=>f.removeEventListener(_,w)},[w]),b(ne,{scope:s,orientation:r,dir:t,loop:R,currentTabStopId:u,onItemFocus:a.useCallback(f=>m(f),[m]),onItemShiftTab:a.useCallback(()=>i(!0),[]),onFocusableItemAdd:a.useCallback(()=>O(f=>f+1),[]),onFocusableItemRemove:a.useCallback(()=>O(f=>f-1),[]),children:b(L.div,{tabIndex:n||H===0?-1:0,"data-orientation":r,...F,ref:d,style:{outline:"none",...e.style},onMouseDown:h(e.onMouseDown,()=>{A.current=!0}),onFocus:h(e.onFocus,f=>{const V=!A.current;if(f.target===f.currentTarget&&V&&!n){const P=new CustomEvent(_,te);if(f.currentTarget.dispatchEvent(P),!P.defaultPrevented){const x=T().filter(S=>S.focusable),Y=x.find(S=>S.active),W=x.find(S=>S.id===u),j=[Y,W,...x].filter(Boolean).map(S=>S.ref.current);B(j,E)}}A.current=!1}),onBlur:h(e.onBlur,()=>i(!1))})})}),K="RovingFocusGroupItem",U=a.forwardRef((e,o)=>{const{__scopeRovingFocusGroup:s,focusable:r=!0,active:R=!1,tabStopId:p,...v}=e,I=J(),l=p||I,c=se(K,s),E=c.currentTabStopId===l,F=z(s),{onFocusableItemAdd:C,onFocusableItemRemove:d}=c;return a.useEffect(()=>{if(r)return C(),()=>d()},[r,C,d]),b(N.ItemSlot,{scope:s,id:l,focusable:r,active:R,children:b(L.span,{tabIndex:E?0:-1,"data-orientation":c.orientation,...v,ref:o,onMouseDown:h(e.onMouseDown,t=>{r?c.onItemFocus(l):t.preventDefault()}),onFocus:h(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:h(e.onKeyDown,t=>{if(t.key==="Tab"&&t.shiftKey){c.onItemShiftTab();return}if(t.target!==t.currentTarget)return;const u=ue(t,c.orientation,c.dir);if(u!==void 0){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;t.preventDefault();let n=F().filter(i=>i.focusable).map(i=>i.ref.current);if(u==="last")n.reverse();else if(u==="prev"||u==="next"){u==="prev"&&n.reverse();const i=n.indexOf(t.currentTarget);n=c.loop?le(n,i+1):n.slice(i+1)}setTimeout(()=>B(n))}})})})});U.displayName=K;var ie={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ae(e,o){return o!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ue(e,o,s){const r=ae(e.key,s);if(!(o==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(o==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return ie[r]}function B(e,o=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:o}),document.activeElement!==s))return}function le(e,o){return e.map((s,r)=>e[(o+r)%e.length])}var be=k,Re=U;function Ce(e){const[o,s]=a.useState(void 0);return Q(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(R=>{if(!Array.isArray(R)||!R.length)return;const p=R[0];let v,I;if("borderBoxSize"in p){const l=p.borderBoxSize,c=Array.isArray(l)?l[0]:l;v=c.inlineSize,I=c.blockSize}else v=e.offsetWidth,I=e.offsetHeight;s({width:v,height:I})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),o}export{Re as I,be as R,ee as a,X as b,Ie as c,Ce as u};
