import { jsxs as Z, jsx as i, Fragment as de } from "react/jsx-runtime";
import * as Pe from "react";
import { useEffect as X, useCallback as V, forwardRef as ze, useState as _, useRef as U, useMemo as Le, useContext as Re } from "react";
import { c as Ie, u as ae, E as Be, X as De, $ as _e, K as me, a as Me, i as Fe, h as Oe, O as re, w as He, y as ue, A as Ae, x as oe, _ as xe, o as ge, b as We, f as Ke, d as Ue, e as Xe, g as Te, j as Ge, l as Ye, C as Ve, S as te, k as ne, m as fe, n as Ze, F as J, T as qe, p as Je, q as Qe, r as et, s as tt, t as nt, v as rt, I as ot, z as it, B as st, D as at, G as he, N as lt, L as ct, H as ut, J as dt, M as mt, P as gt, Q as ft, R as ht, U as pt, V as yt } from "./DSD.DRGuMxXd.js";
import { d as vt } from "./DSD.D2TwdbM_.js";
import { LoadingOverlay as pe, Flex as bt, Alert as Ct, Tooltip as ye, ActionIcon as ve } from "@mantine/core";
import { c as wt } from "./DSD.6z6Plwgb.js";
var Nt = Ie("info-circle", "IconInfoCircle", [
  ["path", { d: "M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", key: "svg-0" }],
  ["path", { d: "M12 9h.01", key: "svg-1" }],
  ["path", { d: "M11 12h1v4h1", key: "svg-2" }]
]);
const be = /* @__PURE__ */ new Map([
  [":)", ["emoji happysmile", "🙂"]],
  [":D", ["emoji veryhappysmile", "😀"]],
  [":(", ["emoji unhappysmile", "🙁"]],
  ["<3", ["emoji heart", "❤"]],
  ["🙂", ["emoji happysmile", "🙂"]],
  ["😀", ["emoji veryhappysmile", "😀"]],
  ["🙁", ["emoji unhappysmile", "🙁"]],
  ["❤", ["emoji heart", "❤"]]
]);
function Et(e) {
  const t = e.getTextContent();
  for (let o = 0; o < t.length; o++) {
    const f = be.get(t[o]) || be.get(t.slice(o, o + 2));
    if (f !== void 0) {
      const [c, g] = f;
      let l;
      o === 0 ? [l] = e.splitText(o + 2) : [, l] = e.splitText(o, o + 2);
      const w = _e(c, g);
      return l.replace(w), w;
    }
  }
  return null;
}
function St(e) {
  let t = e;
  for (; t !== null; ) {
    if (!t.isSimpleText())
      return;
    t = Et(t);
  }
}
function xt(e) {
  X(() => {
    if (!e.hasNodes([Be]))
      throw new Error("EmojisPlugin: EmojiNode not registered on editor");
    return e.registerNodeTransform(De, St);
  }, [e]);
}
function Tt() {
  const [e] = ae();
  return xt(e), null;
}
const $t = /(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])(congrats|congratulations|gratuluju|gratuluji|gratulujeme|blahopřeju|blahopřeji|blahopřejeme|Til lykke|Tillykke|Glückwunsch|Gratuliere|felicitaciones|enhorabuena|paljon onnea|onnittelut|Félicitations|gratula|gratulálok|gratulálunk|congratulazioni|complimenti|おめでとう|おめでとうございます|축하해|축하해요|gratulerer|Gefeliciteerd|gratulacje|Parabéns|parabéns|felicitações|felicitări|мои поздравления|поздравляем|поздравляю|gratulujem|blahoželám|ยินดีด้วย|ขอแสดงความยินดี|tebrikler|tebrik ederim|恭喜|祝贺你|恭喜你|恭喜|恭喜|baie geluk|veels geluk|অভিনন্দন|Čestitam|Čestitke|Čestitamo|Συγχαρητήρια|Μπράβο|અભિનંદન|badhai|बधाई|अभिनंदन|Честитам|Свака част|hongera|வாழ்த்துகள்|வாழ்த்துக்கள்|అభినందనలు|അഭിനന്ദനങ്ങൾ|Chúc mừng|מזל טוב|mazel tov|mazal tov)(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])/i;
function kt() {
  const [e] = ae();
  X(() => {
    if (!e.hasNodes([me]))
      throw new Error("KeywordsPlugin: KeywordNode not registered on editor");
  }, [e]);
  const t = V((f) => Me(f.getTextContent()), []), o = V((f) => {
    const c = $t.exec(f);
    if (c === null)
      return null;
    const g = c[2].length, l = c.index + c[1].length;
    return {
      end: l + g,
      start: l
    };
  }, []);
  return Fe(o, me, t), null;
}
const $e = Object.freeze({ "	": "\\t", "\n": "\\n" }), Ce = new RegExp(Object.keys($e).join("|"), "g"), K = Object.freeze({ ancestorHasNextSibling: "|", ancestorIsLastChild: " ", hasNextSibling: "├", isLastChild: "└", selectedChar: "^", selectedLine: ">" }), jt = [(e) => e.hasFormat("bold") && "Bold", (e) => e.hasFormat("code") && "Code", (e) => e.hasFormat("italic") && "Italic", (e) => e.hasFormat("strikethrough") && "Strikethrough", (e) => e.hasFormat("subscript") && "Subscript", (e) => e.hasFormat("superscript") && "Superscript", (e) => e.hasFormat("underline") && "Underline"], Pt = [(e) => e.hasTextFormat("bold") && "Bold", (e) => e.hasTextFormat("code") && "Code", (e) => e.hasTextFormat("italic") && "Italic", (e) => e.hasTextFormat("strikethrough") && "Strikethrough", (e) => e.hasTextFormat("subscript") && "Subscript", (e) => e.hasTextFormat("superscript") && "Superscript", (e) => e.hasTextFormat("underline") && "Underline"], zt = [(e) => e.isDirectionless() && "Directionless", (e) => e.isUnmergeable() && "Unmergeable"], Lt = [(e) => e.isToken() && "Token", (e) => e.isSegmented() && "Segmented"];
function Rt(e, t, o, f, c = !1) {
  const g = e.getEditorState(), l = e._config, w = e._compositionKey, z = e._editable;
  if (o) {
    let s = "";
    return g.read(() => {
      s = function(d) {
        const p = document.createElement("div");
        return p.innerHTML = d.trim(), je(p, 0).innerHTML;
      }(Oe(e));
    }), s;
  }
  let E = ` root
`;
  const R = g.read(() => {
    const s = re();
    return ke(He(), (d, p) => {
      const $ = `(${d.getKey()})`, I = d.getType() || "", j = d.isSelected();
      E += `${j ? K.selectedLine : " "} ${p.join(" ")} ${$} ${I} ${function(y, N, P = !1) {
        const B = N ? N(y, P) : void 0;
        if (B !== void 0 && B.length > 0) return B;
        if (ge(y)) {
          const r = y.getTextContent(), a = r.length === 0 ? "(empty)" : `"${we(r, P)}"`, n = function(u) {
            return [Ne(u), It(u), Bt(u)].filter(Boolean).join(", ");
          }(y);
          return [a, n.length !== 0 ? `{ ${n} }` : null].filter(Boolean).join(" ").trim();
        }
        if (We(y)) {
          const r = y.getURL(), a = r.length === 0 ? "(empty)" : `"${we(r, P)}"`, n = function(u) {
            return [Dt(u), _t(u), Mt(u)].filter(Boolean).join(", ");
          }(y);
          return [a, n.length !== 0 ? `{ ${n} }` : null].filter(Boolean).join(" ").trim();
        }
        if (Ke(y)) return `ids: [ ${y.getIDs().join(", ")} ]`;
        if (Ue(y)) {
          const r = function(n) {
            let u = Pt.map((S) => S(n)).filter(Boolean).join(", ").toLocaleLowerCase();
            return u !== "" && (u = "format: " + u), u;
          }(y);
          let a = r !== "" ? `{ ${r} }` : "";
          return a += y.__style ? `(${y.__style})` : "", a;
        }
        return "";
      }(d, f, c)}
`, E += function({ indent: y, isSelected: N, node: P, nodeKeyDisplay: B, selection: r, typeDisplay: a }) {
        if (!ge(P) || !ue(r) || !N || xe(P)) return "";
        const n = r.anchor, u = r.focus;
        if (P.getTextContent() === "" || n.getNode() === r.focus.getNode() && n.offset === u.offset) return "";
        const [S, v] = function(H, Q) {
          const q = Q.getStartEndPoints();
          if (oe(Q) || q === null) return [-1, -1];
          const [M, A] = q, ie = H.getTextContent(), ee = ie.length;
          let G = -1, Y = -1;
          if (M.type === "text" && A.type === "text") {
            const x = M.getNode(), W = A.getNode();
            x === W && H === x && M.offset !== A.offset ? [G, Y] = M.offset < A.offset ? [M.offset, A.offset] : [A.offset, M.offset] : [G, Y] = H === x ? x.isBefore(W) ? [M.offset, ee] : [0, M.offset] : H === W ? W.isBefore(x) ? [A.offset, ee] : [0, A.offset] : [0, ee];
          }
          const m = (ie.slice(0, G).match(Ce) || []).length, h = (ie.slice(G, Y).match(Ce) || []).length;
          return [G + m, Y + m + h];
        }(P, r);
        if (S === v) return "";
        const b = y[y.length - 1] === K.hasNextSibling ? K.ancestorHasNextSibling : K.ancestorIsLastChild, O = [...y.slice(0, y.length - 1), b], F = Array(S + 1).fill(" "), L = Array(v - S).fill(K.selectedChar), D = a.length + 2, k = Array(B.length + D).fill(" ");
        return [K.selectedLine, O.join(" "), [...k, ...F, ...L].join("")].join(" ") + `
`;
      }({ indent: p, isSelected: j, node: d, nodeKeyDisplay: $, selection: s, typeDisplay: I });
    }), s === null ? ": null" : ue(s) ? function(d) {
      let p = "";
      const $ = Ne(d);
      p += `: range ${$ !== "" ? `{ ${$} }` : ""} ${d.style !== "" ? `{ style: ${d.style} } ` : ""}`;
      const I = d.anchor, j = d.focus, y = I.offset, N = j.offset;
      return p += `
  ├ anchor { key: ${I.key}, offset: ${y === null ? "null" : y}, type: ${I.type} }`, p += `
  └ focus { key: ${j.key}, offset: ${N === null ? "null" : N}, type: ${j.type} }`, p;
    }(s) : Ae(s) ? function(d) {
      return `: table
  └ { table: ${d.tableKey}, anchorCell: ${d.anchor.key}, focusCell: ${d.focus.key} }`;
    }(s) : function(d) {
      return oe(d) ? `: node
  └ [${Array.from(d._nodes).join(", ")}]` : "";
    }(s);
  });
  if (E += `
 selection` + R, E += `

 commands:`, t.length) for (const { index: s, type: d, payload: p } of t) E += `
  └ ${s}. { type: ${d}, payload: ${p instanceof Event ? p.constructor.name : p} }`;
  else E += `
  └ None dispatched.`;
  const { version: T } = e.constructor;
  return E += `

 editor${T ? ` (v${T})` : ""}:`, E += `
  └ namespace ${l.namespace}`, w !== null && (E += `
  └ compositionKey ${w}`), E += `
  └ editable ${String(z)}`, E;
}
function ke(e, t, o = []) {
  const f = e.getChildren(), c = f.length;
  f.forEach((g, l) => {
    t(g, o.concat(l === c - 1 ? K.isLastChild : K.hasNextSibling)), xe(g) && ke(g, t, o.concat(l === c - 1 ? K.ancestorIsLastChild : K.ancestorHasNextSibling));
  });
}
function we(e, t = !1) {
  const o = Object.entries($e).reduce((f, [c, g]) => f.replace(new RegExp(c, "g"), String(g)), e);
  return t ? o.replace(/[^\s]/g, "*") : o;
}
function It(e) {
  let t = zt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "detail: " + t), t;
}
function Bt(e) {
  let t = Lt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "mode: " + t), t;
}
function Ne(e) {
  let t = jt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "format: " + t), t;
}
function Dt(e) {
  let t = e.getTarget();
  return t != null && (t = "target: " + t), t;
}
function _t(e) {
  let t = e.getRel();
  return t != null && (t = "rel: " + t), t;
}
function Mt(e) {
  let t = e.getTitle();
  return t != null && (t = "title: " + t), t;
}
function je(e, t) {
  const o = new Array(1 + t++).join("  "), f = new Array(t - 1).join("  ");
  let c;
  for (let g = 0; g < e.children.length; g++) c = document.createTextNode(`
` + o), e.insertBefore(c, e.children[g]), je(e.children[g], t), e.lastElementChild === e.children[g] && (c = document.createTextNode(`
` + f), e.appendChild(c));
  return e;
}
const Ft = ze(function({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: f, viewClassName: c, timeTravelPanelClassName: g, editorState: l, setEditorState: w, setEditorReadOnly: z, generateContent: E }, R) {
  const [T, s] = _([]), [d, p] = _(""), [$, I] = _(!1), [j, y] = _(!1), N = U(0), P = U(null), [B, r] = _(!1), [a, n] = _(!1), [u, S] = _(!1), v = U(), b = U(0), O = V((L) => {
    const D = ++b.current;
    E(L).then((k) => {
      D === b.current && p(k);
    }).catch((k) => {
      D === b.current && p(`Error rendering tree: ${k.message}

Stack:
${k.stack}`);
    });
  }, [E]);
  X(() => {
    !u && l._nodeMap.size > 1e3 && (n(!0), !u) || v.current !== l && (v.current = l, O(j), $ || s((L) => [...L, [Date.now(), l]]));
  }, [l, O, j, u, $]);
  const F = T.length;
  return X(() => {
    if (B) {
      let L;
      const D = () => {
        const k = N.current;
        if (k === F - 1) return void r(!1);
        const H = T[k][0], Q = T[k + 1][0];
        L = setTimeout(() => {
          N.current++;
          const q = N.current, M = P.current;
          M !== null && (M.value = String(q)), w(T[q][1]), D();
        }, Q - H);
      };
      return D(), () => {
        clearTimeout(L);
      };
    }
  }, [T, B, F, w]), Z("div", { className: c, children: [!u && a ? Z("div", { style: { padding: 20 }, children: [i("span", { style: { marginRight: 20 }, children: "Detected large EditorState, this can impact debugging performance." }), i("button", { onClick: () => {
    S(!0);
  }, style: { background: "transparent", border: "1px solid white", color: "white", cursor: "pointer", padding: 5 }, children: "Show full tree" })] }) : null, u ? null : i("button", { onClick: () => (O(!j), void y(!j)), className: e, type: "button", children: j ? "Tree" : "Export DOM" }), !$ && (u || !a) && F > 2 && i("button", { onClick: () => {
    z(!0), N.current = F - 1, I(!0);
  }, className: t, type: "button", children: "Time Travel" }), (u || !a) && i("pre", { ref: R, children: d }), $ && (u || !a) && Z("div", { className: g, children: [i("button", { className: f, onClick: () => {
    N.current === F - 1 && (N.current = 1), r(!B);
  }, type: "button", children: B ? "Pause" : "Play" }), i("input", { className: o, ref: P, onChange: (L) => {
    const D = Number(L.target.value), k = T[D];
    k && (N.current = D, w(k[1]));
  }, type: "range", min: "1", max: F - 1 }), i("button", { className: f, onClick: () => {
    z(!1);
    const L = T.length - 1, D = T[L];
    w(D[1]);
    const k = P.current;
    k !== null && (k.value = String(L)), I(!1), r(!1);
  }, type: "button", children: "Exit" })] })] });
});
function Ot(e, t) {
  const o = /* @__PURE__ */ new Set();
  let f = 0;
  for (const [c] of e._commands) o.add(e.registerCommand(c, (g) => (t((l) => {
    f += 1;
    const w = [...l];
    return w.push({ index: f, payload: g, type: c.type ? c.type : "UNKNOWN" }), w.length > 10 && w.shift(), w;
  }), !1), Xe));
  return () => o.forEach((c) => c());
}
function Ht(e) {
  const [t, o] = _([]);
  return X(() => Ot(e, o), [e]), Le(() => t, [t]);
}
function At({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: f, viewClassName: c, timeTravelPanelClassName: g, editor: l, customPrintNode: w }) {
  const z = Pe.createRef(), [E, R] = _(l.getEditorState()), T = Ht(l);
  return X(() => Te(l.registerUpdateListener(({ editorState: s }) => {
    R(s);
  }), l.registerEditableListener(() => {
    R(l.getEditorState());
  })), [l]), X(() => {
    const s = z.current;
    if (s !== null) return s.__lexicalEditor = l, () => {
      s.__lexicalEditor = null;
    };
  }, [l, z]), i(Ft, { treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: f, viewClassName: c, timeTravelPanelClassName: g, setEditorReadOnly: (s) => {
    const d = l.getRootElement();
    d != null && (d.contentEditable = s ? "false" : "true");
  }, editorState: E, setEditorState: (s) => l.setEditorState(s), generateContent: async function(s) {
    return Rt(l, T, s, w);
  }, ref: z });
}
function Wt() {
  const [e] = ae();
  return /* @__PURE__ */ i(
    At,
    {
      viewClassName: "tree-view-output",
      treeTypeButtonClassName: "debug-treetype-button",
      timeTravelPanelClassName: "debug-timetravel-panel",
      timeTravelButtonClassName: "debug-timetravel-button",
      timeTravelPanelSliderClassName: "debug-timetravel-panel-slider",
      timeTravelPanelButtonClassName: "debug-timetravel-panel-button",
      editor: e
    }
  );
}
function ce(e, t, o) {
  return Math.min(Math.max(e, t), o);
}
const C = {
  east: 1,
  north: 8,
  south: 2,
  west: 4
};
function Kt({
  onResizeStart: e,
  onResizeEnd: t,
  buttonRef: o,
  imageRef: f,
  maxWidth: c,
  editor: g,
  showCaption: l,
  setShowCaption: w,
  captionsEnabled: z
}) {
  const E = U(null), R = U({
    priority: "",
    value: "default"
  }), T = U({
    currentHeight: 0,
    currentWidth: 0,
    direction: 0,
    isResizing: !1,
    ratio: 0,
    startHeight: 0,
    startWidth: 0,
    startX: 0,
    startY: 0
  }), s = g.getRootElement(), d = c || (s !== null ? s.getBoundingClientRect().width - 20 : 100), p = s !== null ? s.getBoundingClientRect().height - 20 : 100, $ = 100, I = 100, j = (r) => {
    const a = r === C.east || r === C.west, n = r === C.north || r === C.south, u = r & C.north && r & C.west || r & C.south && r & C.east, S = a ? "ew" : n ? "ns" : u ? "nwse" : "nesw";
    s !== null && s.style.setProperty("cursor", `${S}-resize`, "important"), document.body !== null && (document.body.style.setProperty("cursor", `${S}-resize`, "important"), R.current.value = document.body.style.getPropertyValue("-webkit-user-select"), R.current.priority = document.body.style.getPropertyPriority("-webkit-user-select"), document.body.style.setProperty("-webkit-user-select", "none", "important"));
  }, y = () => {
    s !== null && s.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
      "-webkit-user-select",
      R.current.value,
      R.current.priority
    ));
  }, N = (r, a) => {
    if (!g.isEditable())
      return;
    const n = f.current, u = E.current;
    if (n !== null && u !== null) {
      r.preventDefault();
      const { width: S, height: v } = n.getBoundingClientRect(), b = T.current;
      b.startWidth = S, b.startHeight = v, b.ratio = S / v, b.currentWidth = S, b.currentHeight = v, b.startX = r.clientX, b.startY = r.clientY, b.isResizing = !0, b.direction = a, j(a), e(), u.classList.add("image-control-wrapper--resizing"), n.style.height = `${v}px`, n.style.width = `${S}px`, document.addEventListener("pointermove", P), document.addEventListener("pointerup", B);
    }
  }, P = (r) => {
    const a = f.current, n = T.current, u = n.direction & (C.east | C.west), S = n.direction & (C.south | C.north);
    if (a !== null && n.isResizing)
      if (u && S) {
        let v = Math.floor(n.startX - r.clientX);
        v = n.direction & C.east ? -v : v;
        const b = ce(n.startWidth + v, $, d), O = b / n.ratio;
        a.style.width = `${b}px`, a.style.height = `${O}px`, n.currentHeight = O, n.currentWidth = b;
      } else if (S) {
        let v = Math.floor(n.startY - r.clientY);
        v = n.direction & C.south ? -v : v;
        const b = ce(n.startHeight + v, I, p);
        a.style.height = `${b}px`, n.currentHeight = b;
      } else {
        let v = Math.floor(n.startX - r.clientX);
        v = n.direction & C.east ? -v : v;
        const b = ce(n.startWidth + v, $, d);
        a.style.width = `${b}px`, n.currentWidth = b;
      }
  }, B = () => {
    const r = f.current, a = T.current, n = E.current;
    if (r !== null && n !== null && a.isResizing) {
      const u = a.currentWidth, S = a.currentHeight;
      a.startWidth = 0, a.startHeight = 0, a.ratio = 0, a.startX = 0, a.startY = 0, a.currentWidth = 0, a.currentHeight = 0, a.isResizing = !1, n.classList.remove("image-control-wrapper--resizing"), y(), t(u, S), document.removeEventListener("pointermove", P), document.removeEventListener("pointerup", B);
    }
  };
  return /* @__PURE__ */ Z("div", { ref: E, children: [
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-n",
        onPointerDown: (r) => {
          N(r, C.north);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-ne",
        onPointerDown: (r) => {
          N(r, C.north | C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-e",
        onPointerDown: (r) => {
          N(r, C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-se",
        onPointerDown: (r) => {
          N(r, C.south | C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-s",
        onPointerDown: (r) => {
          N(r, C.south);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-sw",
        onPointerDown: (r) => {
          N(r, C.south | C.west);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-w",
        onPointerDown: (r) => {
          N(r, C.west);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-nw",
        onPointerDown: (r) => {
          N(r, C.north | C.west);
        }
      }
    )
  ] });
}
const Ee = yt(), Se = (e, t, o) => {
  if (!o) {
    t();
    return;
  }
  o(e, t);
};
function Ut({
  altText: e,
  className: t,
  imageRef: o,
  src: f,
  width: c,
  height: g,
  maxWidth: l,
  id: w
}) {
  return /* @__PURE__ */ i(
    "img",
    {
      className: t || void 0,
      src: f,
      alt: e,
      ref: o,
      style: {
        height: g,
        maxWidth: l,
        width: c
      },
      draggable: "false",
      "data-id": w
    }
  );
}
function Jt({
  src: e,
  altText: t,
  nodeKey: o,
  width: f,
  height: c,
  maxWidth: g,
  resizable: l,
  showCaption: w,
  caption: z,
  captionsEnabled: E,
  id: R,
  create: T
}) {
  const s = U(null), d = U(null), [p, $, I] = Ge(o), [j, y] = _(!1), [N, P] = _(!0), [B, r] = _(!1), { isCollabActive: a } = Ye(), [n] = ae(), [u, S] = _(null), v = U(null), { fetchUploadImage: b, fetchDeleteImage: O } = Re(Ve), F = V(
    (m) => {
      if (p && oe(re())) {
        m.preventDefault();
        const x = te(o);
        ne(x) && Se(
          x.__id,
          () => {
            n.update(() => {
              x.remove();
            });
          },
          O
        );
      }
      return !1;
    },
    [p, o]
  ), L = V(
    (m) => {
      const h = re(), x = d.current;
      if (p && oe(h) && h.getNodes().length === 1) {
        if (w)
          return fe(null), m.preventDefault(), z.focus(), !0;
        if (x !== null && x !== document.activeElement)
          return m.preventDefault(), x.focus(), !0;
      }
      return !1;
    },
    [z, p, w]
  ), D = V(
    (m) => v.current === z || d.current === m.target ? (fe(null), n.update(() => {
      $(!0);
      const h = n.getRootElement();
      h !== null && h.focus();
    }), !0) : !1,
    [z, n, $]
  ), k = V(
    (m) => {
      const h = m;
      return j ? !0 : h.target === s.current ? (h.shiftKey ? $(!p) : (I(), $(!0)), !0) : !1;
    },
    [j, p, $, I]
  ), H = V(
    (m) => {
      n.getEditorState().read(() => {
        const h = re();
        m.target.tagName === "IMG" && ue(h) && h.getNodes().length === 1 && n.dispatchCommand(Ee, m);
      });
    },
    [n]
  );
  X(() => {
    if (!e || e.startsWith("data:image/")) return;
    const m = new Image();
    m.src = e, m.onload = () => P(!1), m.onerror = () => {
      P(!1), r(!0);
    };
  }, [e]), X(() => {
    let m = !0;
    const h = n.getRootElement(), x = Te(
      n.registerUpdateListener(({ editorState: W }) => {
        m && S(W.read(() => re()));
      }),
      n.registerCommand(
        tt,
        (W, se) => (v.current = se, !1),
        J
      ),
      n.registerCommand(et, k, J),
      n.registerCommand(Ee, k, J),
      n.registerCommand(Qe, F, J),
      n.registerCommand(Je, F, J),
      n.registerCommand(qe, L, J),
      n.registerCommand(Ze, D, J)
    );
    return h == null || h.addEventListener("contextmenu", H), () => {
      m = !1, x(), h == null || h.removeEventListener("contextmenu", H);
    };
  }, [
    I,
    n,
    j,
    p,
    o,
    F,
    L,
    D,
    k,
    H,
    $
  ]);
  const Q = () => {
    n.update(() => {
      const m = te(o);
      ne(m) && m.setShowCaption(!0);
    });
  }, q = (m, h) => {
    setTimeout(() => {
      y(!1);
    }, 200), n.update(() => {
      const x = te(o);
      ne(x) && x.setWidthAndHeight(m, h);
    });
  }, M = () => {
    y(!0);
  }, { historyState: A } = nt(), {
    settings: { showNestedEditorTreeView: ie }
  } = rt(), ee = p || j, [G, Y] = _(!1);
  return X(() => {
    T && Y(!0);
  }, [T]), e ? /* @__PURE__ */ Z(de, { children: [
    /* @__PURE__ */ Z(
      "div",
      {
        style: {
          display: "inline-block",
          position: "relative"
        },
        children: [
          /* @__PURE__ */ i(
            pe,
            {
              visible: N,
              zIndex: 1e3,
              overlayProps: { backgroundOpacity: 0.5 },
              loaderProps: { size: 24, color: "black" }
            }
          ),
          /* @__PURE__ */ i(
            pe,
            {
              visible: B,
              zIndex: 1e3,
              overlayProps: { backgroundOpacity: 0.5 },
              loaderProps: {
                children: /* @__PURE__ */ i(bt, { bg: "white", maw: 300, justify: "center", children: /* @__PURE__ */ i(
                  Ct,
                  {
                    variant: "light",
                    color: "red",
                    title: "Ошибка загрузки",
                    icon: /* @__PURE__ */ i(Nt, {}),
                    children: "Попробуйте загрузить заново."
                  }
                ) })
              }
            }
          ),
          p && /* @__PURE__ */ Z(de, { children: [
            /* @__PURE__ */ i(ye, { label: "Превью", children: /* @__PURE__ */ i("a", { className: "image-show-icon", href: e, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ i(ve, { variant: "default", color: "gray", "aria-label": "Settings", children: /* @__PURE__ */ i(he, { name: "photo-check" }) }) }) }),
            /* @__PURE__ */ i(ye, { label: "Удалить", children: /* @__PURE__ */ i(
              ve,
              {
                color: "gray",
                "aria-label": "Settings",
                className: "image-delete-icon",
                onClick: (m) => {
                  m.stopPropagation(), Se(
                    R,
                    () => {
                      n.update(() => {
                        if (re()) {
                          const h = te(o);
                          ne(h) && h.remove();
                        }
                        return !1;
                      });
                    },
                    R !== "0" ? O : void 0
                  );
                },
                variant: "default",
                children: /* @__PURE__ */ i(he, { name: "trash" })
              }
            ) })
          ] }),
          l && oe(u) && ee && /* @__PURE__ */ i(
            Kt,
            {
              showCaption: w,
              setShowCaption: Q,
              editor: n,
              buttonRef: d,
              imageRef: s,
              maxWidth: g,
              onResizeStart: M,
              onResizeEnd: q,
              captionsEnabled: E
            }
          ),
          /* @__PURE__ */ i(
            Ut,
            {
              className: ee ? `focused ${oe(u) ? "draggable" : ""}` : null,
              src: e,
              altText: t,
              imageRef: s,
              width: f,
              height: c,
              maxWidth: g || "auto",
              id: R
            }
          )
        ]
      }
    ),
    w && /* @__PURE__ */ i("div", { className: "image-caption-container", children: /* @__PURE__ */ Z(vt, { initialEditor: z, children: [
      /* @__PURE__ */ i(lt, {}),
      /* @__PURE__ */ i(ct, {}),
      /* @__PURE__ */ i(Tt, {}),
      /* @__PURE__ */ i(ut, {}),
      /* @__PURE__ */ i(kt, {}),
      a ? /* @__PURE__ */ i(
        dt,
        {
          id: z.getKey(),
          providerFactory: wt,
          shouldBootstrap: !0
        }
      ) : /* @__PURE__ */ i(mt, { externalHistoryState: A }),
      /* @__PURE__ */ i(
        gt,
        {
          contentEditable: /* @__PURE__ */ i(ft, { className: "ImageNode__contentEditable" }),
          placeholder: /* @__PURE__ */ i(ht, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
          ErrorBoundary: pt
        }
      ),
      ie === !0 ? /* @__PURE__ */ i(Wt, {}) : null
    ] }) })
  ] }) : /* @__PURE__ */ i(
    ot,
    {
      uploading: !1,
      onUpload: (m) => {
        !b || !m.length || m.forEach((h, x) => {
          b(h, (W, se) => {
            x === 0 ? n.update(() => {
              const le = te(o);
              ne(le) && (le.setSrc(W), le.setId(se));
            }) : n.dispatchCommand(it, {
              altText: "",
              src: W,
              id: se
            });
          });
        });
      },
      popoverProps: {
        opened: G,
        position: "bottom",
        onChange: Y
      },
      onChange: (m) => {
        n.update(() => {
          const h = te(o);
          ne(h) && h.setSrc(m);
        });
      },
      children: /* @__PURE__ */ i(
        st,
        {
          title: at("editor.image.add_photo"),
          icon: "photo",
          onClick: () => Y(!G)
        }
      )
    }
  );
}
export {
  Ee as RIGHT_CLICK_IMAGE_COMMAND,
  Jt as default
};
