import*as e from"react";import{jsx as t}from"react/jsx-runtime";function r(r,n){const o=e.createContext(n),c=r=>{const{children:n,...c}=r,s=e.useMemo((()=>c),Object.values(c));return t(o.Provider,{value:s,children:n})};return c.displayName=r+"Provider",[c,function(t){const c=e.useContext(o);if(c)return c;if(void 0!==n)return n;throw new Error(`\`${t}\` must be used within \`${r}\``)}]}function n(r,n=[]){let c=[];const s=()=>{const t=c.map((t=>e.createContext(t)));return function(n){const o=n?.[r]||t;return e.useMemo((()=>({[`__scope${r}`]:{...n,[r]:o}})),[n,o])}};return s.scopeName=r,[function(n,o){const s=e.createContext(o),u=c.length;c=[...c,o];const i=n=>{const{scope:o,children:c,...i}=n,a=o?.[r]?.[u]||s,m=e.useMemo((()=>i),Object.values(i));return t(a.Provider,{value:m,children:c})};return i.displayName=n+"Provider",[i,function(t,c){const i=c?.[r]?.[u]||s,a=e.useContext(i);if(a)return a;if(void 0!==o)return o;throw new Error(`\`${t}\` must be used within \`${n}\``)}]},o(s,...n)]}function o(...t){const r=t[0];if(1===t.length)return r;const n=()=>{const n=t.map((e=>({useScope:e(),scopeName:e.scopeName})));return function(t){const o=n.reduce(((e,{useScope:r,scopeName:n})=>({...e,...r(t)[`__scope${n}`]})),{});return e.useMemo((()=>({[`__scope${r.scopeName}`]:o})),[o])}};return n.scopeName=r.scopeName,n}export{r as createContext,n as createContextScope};
//# sourceMappingURL=index.js.map
