import{r as s,j as E}from"./index-gX9iSPDQ.js";import{b as z,l as q,d as J,P as _,e as b,f as D,k as Q,u as X,j as Z,o as x}from"./createLucideIcon-W0Ra_zwb.js";var h="rovingFocusGroup.onEntryFocus",$={bubbles:!1,cancelable:!0},w="RovingFocusGroup",[M,U,ee]=q(w),[te,ge]=z(w,[ee]),[ne,oe]=te(w),L=s.forwardRef((e,t)=>E.jsx(M.Provider,{scope:e.__scopeRovingFocusGroup,children:E.jsx(M.Slot,{scope:e.__scopeRovingFocusGroup,children:E.jsx(re,{...e,ref:t})})}));L.displayName=w;var re=s.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,orientation:n,loop:c=!1,dir:p,currentTabStopId:F,defaultCurrentTabStopId:R,onCurrentTabStopIdChange:i,onEntryFocus:r,preventScrollOnEntryFocus:v=!1,...g}=e,l=s.useRef(null),f=D(t,l),a=Q(p),[d=null,A]=X({prop:F,defaultProp:R,onChange:i}),[m,I]=s.useState(!1),S=Z(r),K=U(o),C=s.useRef(!1),[W,P]=s.useState(0);return s.useEffect(()=>{const u=l.current;if(u)return u.addEventListener(h,S),()=>u.removeEventListener(h,S)},[S]),E.jsx(ne,{scope:o,orientation:n,dir:a,loop:c,currentTabStopId:d,onItemFocus:s.useCallback(u=>A(u),[A]),onItemShiftTab:s.useCallback(()=>I(!0),[]),onFocusableItemAdd:s.useCallback(()=>P(u=>u+1),[]),onFocusableItemRemove:s.useCallback(()=>P(u=>u-1),[]),children:E.jsx(_.div,{tabIndex:m||W===0?-1:0,"data-orientation":n,...g,ref:f,style:{outline:"none",...e.style},onMouseDown:b(e.onMouseDown,()=>{C.current=!0}),onFocus:b(e.onFocus,u=>{const B=!C.current;if(u.target===u.currentTarget&&B&&!m){const y=new CustomEvent(h,$);if(u.currentTarget.dispatchEvent(y),!y.defaultPrevented){const O=K().filter(N=>N.focusable),V=O.find(N=>N.active),Y=O.find(N=>N.id===d),H=[V,Y,...O].filter(Boolean).map(N=>N.ref.current);k(H,v)}}C.current=!1}),onBlur:b(e.onBlur,()=>I(!1))})})}),G="RovingFocusGroupItem",j=s.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,focusable:n=!0,active:c=!1,tabStopId:p,...F}=e,R=J(),i=p||R,r=oe(G,o),v=r.currentTabStopId===i,g=U(o),{onFocusableItemAdd:l,onFocusableItemRemove:f}=r;return s.useEffect(()=>{if(n)return l(),()=>f()},[n,l,f]),E.jsx(M.ItemSlot,{scope:o,id:i,focusable:n,active:c,children:E.jsx(_.span,{tabIndex:v?0:-1,"data-orientation":r.orientation,...F,ref:t,onMouseDown:b(e.onMouseDown,a=>{n?r.onItemFocus(i):a.preventDefault()}),onFocus:b(e.onFocus,()=>r.onItemFocus(i)),onKeyDown:b(e.onKeyDown,a=>{if(a.key==="Tab"&&a.shiftKey){r.onItemShiftTab();return}if(a.target!==a.currentTarget)return;const d=ie(a,r.orientation,r.dir);if(d!==void 0){if(a.metaKey||a.ctrlKey||a.altKey||a.shiftKey)return;a.preventDefault();let m=g().filter(I=>I.focusable).map(I=>I.ref.current);if(d==="last")m.reverse();else if(d==="prev"||d==="next"){d==="prev"&&m.reverse();const I=m.indexOf(a.currentTarget);m=r.loop?ce(m,I+1):m.slice(I+1)}setTimeout(()=>k(m))}})})})});j.displayName=G;var se={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ae(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function ie(e,t,o){const n=ae(e.key,o);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return se[n]}function k(e,t=!1){const o=document.activeElement;for(const n of e)if(n===o||(n.focus({preventScroll:t}),document.activeElement!==o))return}function ce(e,t){return e.map((o,n)=>e[(t+n)%e.length])}var Ie=L,Re=j;function ue(e,t){return s.useReducer((o,n)=>t[o][n]??o,e)}var fe=e=>{const{present:t,children:o}=e,n=le(t),c=typeof o=="function"?o({present:n.isPresent}):s.Children.only(o),p=D(n.ref,de(c));return typeof o=="function"||n.isPresent?s.cloneElement(c,{ref:p}):null};fe.displayName="Presence";function le(e){const[t,o]=s.useState(),n=s.useRef({}),c=s.useRef(e),p=s.useRef("none"),F=e?"mounted":"unmounted",[R,i]=ue(F,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return s.useEffect(()=>{const r=T(n.current);p.current=R==="mounted"?r:"none"},[R]),x(()=>{const r=n.current,v=c.current;if(v!==e){const l=p.current,f=T(r);e?i("MOUNT"):f==="none"||(r==null?void 0:r.display)==="none"?i("UNMOUNT"):i(v&&l!==f?"ANIMATION_OUT":"UNMOUNT"),c.current=e}},[e,i]),x(()=>{if(t){let r;const v=t.ownerDocument.defaultView??window,g=f=>{const d=T(n.current).includes(f.animationName);if(f.target===t&&d&&(i("ANIMATION_END"),!c.current)){const A=t.style.animationFillMode;t.style.animationFillMode="forwards",r=v.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=A)})}},l=f=>{f.target===t&&(p.current=T(n.current))};return t.addEventListener("animationstart",l),t.addEventListener("animationcancel",g),t.addEventListener("animationend",g),()=>{v.clearTimeout(r),t.removeEventListener("animationstart",l),t.removeEventListener("animationcancel",g),t.removeEventListener("animationend",g)}}else i("ANIMATION_END")},[t,i]),{isPresent:["mounted","unmountSuspended"].includes(R),ref:s.useCallback(r=>{r&&(n.current=getComputedStyle(r)),o(r)},[])}}function T(e){return(e==null?void 0:e.animationName)||"none"}function de(e){var n,c;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,o=t&&"isReactWarning"in t&&t.isReactWarning;return o?e.ref:(t=(c=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:c.get,o=t&&"isReactWarning"in t&&t.isReactWarning,o?e.props.ref:e.props.ref||e.ref)}export{Re as I,fe as P,Ie as R,ge as c};
