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