import { l as E } from "./LexicalCollaborationContext.prod-CKLiaJe8.js";
import { aF as m, aG as k } from "./index-Buqt2Jsq.js";
import * as y from "react";
import { useRef as C, useContext as D, useMemo as K, useEffect as p } from "react";
var O = 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 h(e) {
  const r = e.transform();
  return r !== null ? /* @__PURE__ */ new Set([r]) : /* @__PURE__ */ new Set();
}
function R({ initialEditor: e, children: r, initialNodes: n, initialTheme: g, skipCollabChecks: v }) {
  const d = C(!1), i = D(m);
  i == null && O(9);
  const [s, { getTheme: _ }] = i, w = K(() => {
    const a = g || _() || void 0, b = k(i, a);
    if (a !== void 0 && (e._config.theme = a), e._parentEditor = s, n)
      for (let t of n) {
        let l = null, o = null;
        if (typeof t != "function") {
          const f = t;
          t = f.replace, l = f.with, o = f.withKlass || null;
        }
        const u = e._nodes.get(t.getType());
        e._nodes.set(t.getType(), { exportDOM: u ? u.exportDOM : void 0, klass: t, replace: l, replaceWithKlass: o, transforms: h(t) });
      }
    else {
      const t = e._nodes = new Map(s._nodes);
      for (const [l, o] of t)
        e._nodes.set(l, { exportDOM: o.exportDOM, klass: o.klass, replace: o.replace, replaceWithKlass: o.replaceWithKlass, transforms: h(o.klass) });
    }
    return e._config.namespace = s._config.namespace, e._editable = s._editable, [e, b];
  }, []), { isCollabActive: x, yjsDocMap: M } = E(), c = v || d.current || M.has(e.getKey());
  return p(() => {
    c && (d.current = !0);
  }, [c]), p(() => s.registerEditableListener((a) => {
    e.setEditable(a);
  }), [e, s]), y.createElement(m.Provider, { value: w }, !x || c ? r : null);
}
export {
  R as p
};
