"use client";
import { useLexicalComposerContext as E } from "./LexicalComposerContext.prod.js";
import { useLexicalEditable as b } from "./useLexicalEditable.prod.js";
import { $canShowPlaceholderCurry as j } from "../text/LexicalText.prod.js";
import { mergeRegister as y } from "../utils/LexicalUtils.prod.js";
import { useState as w, useMemo as C, useLayoutEffect as D, useEffect as x, Suspense as P } from "react";
import { flushSync as R, createPortal as $ } from "react-dom";
import { jsx as m, jsxs as k, Fragment as v } from "react/jsx-runtime";
import { registerDragonSupport as B } from "../dragon/LexicalDragon.prod.js";
import { registerRichText as M } from "../rich-text/LexicalRichText.prod.js";
const d = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? D : x;
function h(r) {
  return r.getEditorState().read(j(r.isComposing()));
}
function H({ contentEditable: r, placeholder: u = null, ErrorBoundary: a }) {
  const [n] = E(), o = (function(e, i) {
    const [t, s] = w((() => e.getDecorators()));
    return d((() => e.registerDecoratorListener(((c) => {
      R((() => {
        s(c);
      }));
    }))), [e]), x((() => {
      s(e.getDecorators());
    }), [e]), C((() => {
      const c = [], p = Object.keys(t);
      for (let l = 0; l < p.length; l++) {
        const f = p[l], L = m(i, { onError: (S) => e._onError(S), children: m(P, { fallback: null, children: t[f] }) }), g = e.getElementByKey(f);
        g !== null && c.push($(L, g, f));
      }
      return c;
    }), [i, t, e]);
  })(n, a);
  return (function(e) {
    d((() => y(M(e), B(e))), [e]);
  })(n), k(v, { children: [r, m(T, { content: u }), o] });
}
function T({ content: r }) {
  const [u] = E(), a = (function(o) {
    const [e, i] = w((() => h(o)));
    return d((() => {
      function t() {
        const s = h(o);
        i(s);
      }
      return t(), y(o.registerUpdateListener((() => {
        t();
      })), o.registerEditableListener((() => {
        t();
      })));
    }), [o]), e;
  })(u), n = b();
  return a ? typeof r == "function" ? r(n) : r : null;
}
export {
  H as RichTextPlugin
};
