import { __exports as i } from "./index-LexicalComposer.dev2.js";
import { __require as w } from "./index-LexicalComposerContext2.js";
import { __require as g } from "./index-Lexical.js";
import h from "react";
var f;
function $() {
  if (f) return i;
  f = 1;
  var m = w(), a = g(), c = h;
  const d = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
  var p = d ? c.useLayoutEffect : c.useEffect;
  const s = {
    tag: "history-merge"
  };
  function E({
    initialConfig: e,
    children: t
  }) {
    const o = c.useMemo(
      () => {
        const {
          theme: r,
          namespace: n,
          editor__DEPRECATED: _,
          nodes: C,
          onError: L,
          editorState: v,
          html: y
        } = e, b = m.createLexicalComposerContext(null, r);
        let u = _ || null;
        if (u === null) {
          const l = a.createEditor({
            editable: e.editable,
            html: y,
            namespace: n,
            nodes: C,
            onError: (R) => L(R, l),
            theme: r
          });
          x(l, v), u = l;
        }
        return [u, b];
      },
      // We only do this for init
      // eslint-disable-next-line react-hooks/exhaustive-deps
      []
    );
    return p(() => {
      const r = e.editable, [n] = o;
      n.setEditable(r !== void 0 ? r : !0);
    }, []), /* @__PURE__ */ c.createElement(m.LexicalComposerContext.Provider, {
      value: o
    }, t);
  }
  function x(e, t) {
    if (t !== null) {
      if (t === void 0)
        e.update(() => {
          const o = a.$getRoot();
          if (o.isEmpty()) {
            const r = a.$createParagraphNode();
            o.append(r);
            const n = d ? document.activeElement : null;
            (a.$getSelection() !== null || n !== null && n === e.getRootElement()) && r.select();
          }
        }, s);
      else if (t !== null)
        switch (typeof t) {
          case "string": {
            const o = e.parseEditorState(t);
            e.setEditorState(o, s);
            break;
          }
          case "object": {
            e.setEditorState(t, s);
            break;
          }
          case "function": {
            e.update(() => {
              a.$getRoot().isEmpty() && t(e);
            }, s);
            break;
          }
        }
    }
  }
  return i.LexicalComposer = E, i;
}
export {
  $ as __require
};
