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