import { createContext as E, useContext as x, useRef as O, useMemo as j, useEffect as u } from "react";
import { x as f, y as k, j as K } from "./main-vElH084q.js";
const b = [["Cat", "rgb(125, 50, 0)"], ["Dog", "rgb(100, 0, 0)"], ["Rabbit", "rgb(150, 0, 0)"], ["Frog", "rgb(200, 0, 0)"], ["Fox", "rgb(200, 75, 0)"], ["Hedgehog", "rgb(0, 75, 0)"], ["Pigeon", "rgb(0, 125, 0)"], ["Squirrel", "rgb(75, 100, 0)"], ["Bear", "rgb(125, 100, 0)"], ["Tiger", "rgb(0, 0, 150)"], ["Leopard", "rgb(0, 0, 200)"], ["Zebra", "rgb(0, 0, 250)"], ["Wolf", "rgb(0, 100, 150)"], ["Owl", "rgb(0, 100, 100)"], ["Gull", "rgb(100, 0, 100)"], ["Squid", "rgb(150, 0, 150)"]], h = b[Math.floor(Math.random() * b.length)], S = E({ clientID: 0, color: h[1], isCollabActive: !1, name: h[0], yjsDocMap: /* @__PURE__ */ new Map() });
function T(e, r) {
  return x(S);
}
function L(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
var P = L(function(e) {
  const r = new URLSearchParams();
  r.append("code", e);
  for (let n = 1; n < arguments.length; n++)
    r.append("v", arguments[n]);
  throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${r} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
});
function m(e) {
  const r = e.transform();
  return r !== null ? /* @__PURE__ */ new Set([r]) : /* @__PURE__ */ new Set();
}
function $({ initialEditor: e, children: r, initialNodes: n, initialTheme: v, skipCollabChecks: M }) {
  const d = O(!1), s = x(f);
  s == null && P(9);
  const [l, { getTheme: _ }] = s, w = j(() => {
    const a = v || _() || void 0, C = k(s, a);
    if (a !== void 0 && (e._config.theme = a), e._parentEditor = l, n)
      for (let t of n) {
        let i = null, o = null;
        if (typeof t != "function") {
          const g = t;
          t = g.replace, i = g.with, o = g.withKlass || null;
        }
        const p = e._nodes.get(t.getType());
        e._nodes.set(t.getType(), { exportDOM: p ? p.exportDOM : void 0, klass: t, replace: i, replaceWithKlass: o, transforms: m(t) });
      }
    else {
      const t = e._nodes = new Map(l._nodes);
      for (const [i, o] of t)
        e._nodes.set(i, { exportDOM: o.exportDOM, klass: o.klass, replace: o.replace, replaceWithKlass: o.replaceWithKlass, transforms: m(o.klass) });
    }
    return e._config.namespace = l._config.namespace, e._editable = l._editable, [e, C];
  }, []), { isCollabActive: y, yjsDocMap: D } = T(), c = M || d.current || D.has(e.getKey());
  return u(() => {
    c && (d.current = !0);
  }, [c]), u(() => l.registerEditableListener((a) => {
    e.setEditable(a);
  }), [e, l]), K.jsx(f.Provider, { value: w, children: !y || c ? r : null });
}
export {
  $ as d
};
