import{r as i,j as h,R as E}from"../react-D4HIU6wz.js";import{c as A,u as v}from"./react-compose-refs-CQmBY8ZD.js";function O(e,o=[]){let n=[];function r(s,l){const c=i.createContext(l),u=n.length;n=[...n,l];function a(p){const{scope:d,children:I,...R}=p,m=(d==null?void 0:d[e][u])||c,f=i.useMemo(()=>R,Object.values(R));return h.jsx(m.Provider,{value:f,children:I})}function C(p,d){const I=(d==null?void 0:d[e][u])||c,R=i.useContext(I);if(R)return R;if(l!==void 0)return l;throw new Error(`\`${p}\` must be used within \`${s}\``)}return a.displayName=s+"Provider",[a,C]}const t=()=>{const s=n.map(l=>i.createContext(l));return function(c){const u=(c==null?void 0:c[e])||s;return i.useMemo(()=>({[`__scope${e}`]:{...c,[e]:u}}),[c,u])}};return t.scopeName=e,[r,j(t,...o)]}function j(...e){const o=e[0];if(e.length===1)return o;const n=()=>{const r=e.map(t=>({useScope:t(),scopeName:t.scopeName}));return function(s){const l=r.reduce((c,{useScope:u,scopeName:a})=>{const p=u(s)[`__scope${a}`];return{...c,...p}},{});return i.useMemo(()=>({[`__scope${o.scopeName}`]:l}),[l])}};return n.scopeName=o.scopeName,n}function P(e){const o=T(e),n=i.forwardRef((r,t)=>{const{children:s,...l}=r,c=i.Children.toArray(s),u=c.find(w);if(u){const a=u.props.children,C=c.map(p=>p===u?i.Children.count(a)>1?i.Children.only(null):i.isValidElement(a)?a.props.children:null:p);return h.jsx(o,{...l,ref:t,children:i.isValidElement(a)?i.cloneElement(a,void 0,C):null})}return h.jsx(o,{...l,ref:t,children:s})});return n.displayName=`${e}.Slot`,n}function T(e){const o=i.forwardRef((n,r)=>{const{children:t,...s}=n;if(i.isValidElement(t)){const l=V(t),c=$(s,t.props);return t.type!==i.Fragment&&(c.ref=r?A(r,l):l),i.cloneElement(t,c)}return i.Children.count(t)>1?i.Children.only(null):null});return o.displayName=`${e}.SlotClone`,o}var b=Symbol("radix.slottable");function w(e){return i.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===b}function $(e,o){const n={...o};for(const r in o){const t=e[r],s=o[r];/^on[A-Z]/.test(r)?t&&s?n[r]=(...c)=>{const u=s(...c);return t(...c),u}:t&&(n[r]=t):r==="style"?n[r]={...t,...s}:r==="className"&&(n[r]=[t,s].filter(Boolean).join(" "))}return{...e,...n}}function V(e){var r,t;let o=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=o&&"isReactWarning"in o&&o.isReactWarning;return n?e.ref:(o=(t=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:t.get,n=o&&"isReactWarning"in o&&o.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}function W(e){const o=e+"CollectionProvider",[n,r]=O(o),[t,s]=n(o,{collectionRef:{current:null},itemMap:new Map}),l=m=>{const{scope:f,children:_}=m,x=E.useRef(null),S=E.useRef(new Map).current;return h.jsx(t,{scope:f,itemMap:S,collectionRef:x,children:_})};l.displayName=o;const c=e+"CollectionSlot",u=P(c),a=E.forwardRef((m,f)=>{const{scope:_,children:x}=m,S=s(c,_),y=v(f,S.collectionRef);return h.jsx(u,{ref:y,children:x})});a.displayName=c;const C=e+"CollectionItemSlot",p="data-radix-collection-item",d=P(C),I=E.forwardRef((m,f)=>{const{scope:_,children:x,...S}=m,y=E.useRef(null),g=v(f,y),M=s(C,_);return E.useEffect(()=>(M.itemMap.set(y,{ref:y,...S}),()=>void M.itemMap.delete(y))),h.jsx(d,{[p]:"",ref:g,children:x})});I.displayName=C;function R(m){const f=s(e+"CollectionConsumer",m);return E.useCallback(()=>{const x=f.collectionRef.current;if(!x)return[];const S=Array.from(x.querySelectorAll(`[${p}]`));return Array.from(f.itemMap.values()).sort((M,N)=>S.indexOf(M.ref.current)-S.indexOf(N.ref.current))},[f.collectionRef,f.itemMap])}return[{Provider:l,Slot:a,ItemSlot:I},R,r]}export{W as c};