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