import{r as p,a9 as P,f as _,c as j,l as C,u as w,j as A,aa as y}from"./index-BMIwdYku.js";var L=P[" useInsertionEffect ".trim().toString()]||_;function D({prop:e,defaultProp:s,onChange:c=()=>{},caller:R}){const[a,t,r]=$({defaultProp:s,onChange:c}),o=e!==void 0,x=o?e:a;{const n=p.useRef(e!==void 0);p.useEffect(()=>{const i=n.current;i!==o&&console.warn(`${R} is changing from ${i?"controlled":"uncontrolled"} to ${o?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),n.current=o},[o,R])}const v=p.useCallback(n=>{var i;if(o){const I=b(n)?n(e):n;I!==e&&((i=r.current)==null||i.call(r,I))}else t(n)},[o,e,t,r]);return[x,v]}function $({defaultProp:e,onChange:s}){const[c,R]=p.useState(e),a=p.useRef(c),t=p.useRef(s);return L(()=>{t.current=s},[s]),p.useEffect(()=>{var r;a.current!==c&&((r=t.current)==null||r.call(t,c),a.current=c)},[c,a]),[c,R,t]}function b(e){return typeof e=="function"}function g(e){const s=e+"CollectionProvider",[c,R]=j(s),[a,t]=c(s,{collectionRef:{current:null},itemMap:new Map}),r=d=>{const{scope:l,children:S}=d,u=C.useRef(null),f=C.useRef(new Map).current;return A.jsx(a,{scope:l,itemMap:f,collectionRef:u,children:S})};r.displayName=s;const o=e+"CollectionSlot",x=y(o),v=C.forwardRef((d,l)=>{const{scope:S,children:u}=d,f=t(o,S),m=w(l,f.collectionRef);return A.jsx(x,{ref:m,children:u})});v.displayName=o;const n=e+"CollectionItemSlot",i="data-radix-collection-item",I=y(n),M=C.forwardRef((d,l)=>{const{scope:S,children:u,...f}=d,m=C.useRef(null),N=w(l,m),E=t(n,S);return C.useEffect(()=>(E.itemMap.set(m,{ref:m,...f}),()=>void E.itemMap.delete(m))),A.jsx(I,{[i]:"",ref:N,children:u})});M.displayName=n;function T(d){const l=t(e+"CollectionConsumer",d);return C.useCallback(()=>{const u=l.collectionRef.current;if(!u)return[];const f=Array.from(u.querySelectorAll(`[${i}]`));return Array.from(l.itemMap.values()).sort((E,O)=>f.indexOf(E.ref.current)-f.indexOf(O.ref.current))},[l.collectionRef,l.itemMap])}return[{Provider:r,Slot:v,ItemSlot:M},T,R]}export{g as c,D as u};