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