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