import{bE as T,V as c,bL as m,bD as $,r as f}from"./index-f9c70843.js";function h(e){const t=e+"CollectionProvider",[C,x]=T(t),[b,d]=C(t,{collectionRef:{current:null},itemMap:new Map}),R=s=>{const{scope:o,children:i}=s,r=c.useRef(null),n=c.useRef(new Map).current;return c.createElement(b,{scope:o,itemMap:n,collectionRef:r},i)},M=e+"CollectionSlot",E=c.forwardRef((s,o)=>{const{scope:i,children:r}=s,n=d(M,i),l=m(o,n.collectionRef);return c.createElement($,{ref:l},r)}),I=e+"CollectionItemSlot",u="data-radix-collection-item",v=c.forwardRef((s,o)=>{const{scope:i,children:r,...n}=s,l=c.useRef(null),p=m(o,l),a=d(I,i);return c.useEffect(()=>(a.itemMap.set(l,{ref:l,...n}),()=>void a.itemMap.delete(l))),c.createElement($,{[u]:"",ref:p},r)});function S(s){const o=d(e+"CollectionConsumer",s);return c.useCallback(()=>{const r=o.collectionRef.current;if(!r)return[];const n=Array.from(r.querySelectorAll(`[${u}]`));return Array.from(o.itemMap.values()).sort((a,A)=>n.indexOf(a.ref.current)-n.indexOf(A.ref.current))},[o.collectionRef,o.itemMap])}return[{Provider:R,Slot:E,ItemSlot:v},S,x]}const O=f.createContext(void 0);function D(e){const t=f.useContext(O);return e||t||"ltr"}function N(e){const t=f.useRef({value:e,previous:e});return f.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}export{h as $,D as a,N as b};
