import { jsx as i, jsxs as d } from "react/jsx-runtime";
import { useCallback as E, useMemo as I, useRef as be, useImperativeHandle as De, useState as se, useEffect as Ke } from "react";
import { createSlotRecipeContext as Oe, mergeRefs as He, useSlotRecipe as Ne } from "@chakra-ui/react";
import { e as Pe } from "./extract-style-props-CMyV-es-.es.js";
import { n as $e } from "./index-N3Xxo-X9.es.js";
import { Transforms as R, Text as j, Element as _, Editor as b, Range as xe, createEditor as ze } from "slate";
import { ReactEditor as ne, useSlate as Z, withReact as _e, Slate as qe, Editable as Be } from "slate-react";
import { withHistory as Ue } from "slate-history";
import { $ as Ve } from "./useObjectRef-CaJ5pgjX.es.js";
import { I as B } from "./icon-toggle-button-DuHJLVGq.es.js";
import { G as ae } from "./group-DaIVSXIi.es.js";
import { MoreHoriz as We, FormatStrikethrough as je, Code as Ge, KeyboardArrowDown as Xe, FormatBold as Ye, FormatItalic as Qe, FormatUnderlined as Ze, FormatListBulleted as Je, FormatListNumbered as et, Undo as tt, Redo as rt } from "@commercetools/nimbus-icons";
import { n as U, u as Se } from "./normalize-messages-BN9BAFXe.es.js";
import { M as v } from "./menu-5MhPfzoZ.es.js";
import { T as g } from "./tooltip-cwtXJhIK.es.js";
import { I as oe } from "./icon-button-DQaOMIAe.es.js";
import { B as $ } from "./box-DuBoAZvq.es.js";
import { T as A } from "./text-iTgAZrNO.es.js";
import { T as nt } from "./toolbar-CyTAGF7Q.es.js";
import { S as le } from "./separator-D5lH4oxr.es.js";
import { T as ce } from "./toggle-button-group-8QKQg546.es.js";
import { V } from "./visually-hidden-DVHn3y3w.es.js";
function Te(t) {
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
}
const { withProvider: ot, withContext: we } = /* @__PURE__ */ Oe({
  key: "nimbusRichTextInput"
}), it = /* @__PURE__ */ ot("div", "root"), st = /* @__PURE__ */ we("div", "toolbar"), at = /* @__PURE__ */ we("div", "editable"), ke = (t) => E(
  (e) => () => {
    const { selection: r } = t;
    e(), r && !t.selection && R.select(t, r), ne.isFocused(t) || ne.focus(t);
  },
  [t]
), ue = {
  "mod+b": "bold",
  "mod+i": "italic",
  "mod+u": "underline",
  "mod+`": "code"
}, X = {
  placeholder: "Start typing...",
  isDisabled: !1,
  isReadOnly: !1,
  autoFocus: !1
}, de = {
  blockquote: "block-quote",
  p: "paragraph",
  pre: "code",
  h1: "heading-one",
  h2: "heading-two",
  h3: "heading-three",
  h4: "heading-four",
  h5: "heading-five",
  ul: "bulleted-list",
  ol: "numbered-list",
  li: "list-item",
  a: "link"
}, he = {
  strong: "bold",
  b: "bold",
  em: "italic",
  i: "italic",
  u: "underline",
  code: "code",
  sup: "superscript",
  sub: "subscript",
  del: "strikethrough",
  s: "strikethrough"
}, Q = {
  STRIKETHROUGH: "strikethrough",
  CODE: "code",
  SUPERSCRIPT: "superscript",
  SUBSCRIPT: "subscript"
}, lt = [
  Q.STRIKETHROUGH,
  Q.CODE
], ct = [
  Q.SUPERSCRIPT,
  Q.SUBSCRIPT
], ut = (t) => [
  {
    id: "paragraph",
    label: t("paragraph"),
    props: {
      textStyle: "md",
      fontWeight: "500"
    }
  },
  {
    id: "heading-one",
    label: t("headingOne"),
    props: {
      textStyle: "2xl",
      fontWeight: "500"
    }
  },
  {
    id: "heading-two",
    label: t("headingTwo"),
    props: {
      textStyle: "xl",
      fontWeight: "500"
    }
  },
  {
    id: "heading-three",
    label: t("headingThree"),
    props: {
      textStyle: "lg",
      fontWeight: "500"
    }
  },
  {
    id: "heading-four",
    label: t("headingFour"),
    props: {
      textStyle: "md",
      fontWeight: "500"
    }
  },
  {
    id: "heading-five",
    label: t("headingFive"),
    props: {
      textStyle: "xs",
      fontWeight: "500"
    }
  },
  {
    id: "block-quote",
    label: t("quote"),
    props: {
      textStyle: "md",
      fontWeight: "400"
    }
  }
], dt = [
  "heading-one",
  "heading-two",
  "heading-three",
  "heading-four",
  "heading-five",
  "block-quote"
];
var ee, pe;
function ht() {
  if (pe) return ee;
  pe = 1;
  var t = /["'&<>]/;
  ee = e;
  function e(r) {
    var o = "" + r, n = t.exec(o);
    if (!n)
      return o;
    var l, c = "", u = 0, h = 0;
    for (u = n.index; u < o.length; u++) {
      switch (o.charCodeAt(u)) {
        case 34:
          l = "&quot;";
          break;
        case 38:
          l = "&amp;";
          break;
        case 39:
          l = "&#39;";
          break;
        case 60:
          l = "&lt;";
          break;
        case 62:
          l = "&gt;";
          break;
        default:
          continue;
      }
      h !== u && (c += o.substring(h, u)), h = u + 1, c += l;
    }
    return h !== u ? c + o.substring(h, u) : c;
  }
  return ee;
}
var pt = /* @__PURE__ */ ht();
const Y = /* @__PURE__ */ Te(pt), Ce = `​
`, O = () => [
  {
    type: "paragraph",
    children: [{ text: "" }]
  }
], ft = (t) => t.map(ve).join(""), ve = (t) => {
  if (j.isText(t)) {
    const o = t;
    let n = Y(o.text);
    return o.bold && (n = `<strong>${n}</strong>`), o.code && (n = `<code>${n}</code>`), o.italic && (n = `<em>${n}</em>`), o.underline && (n = `<u>${n}</u>`), o.superscript && (n = `<sup>${n}</sup>`), o.subscript && (n = `<sub>${n}</sub>`), o.strikethrough && (n = `<del>${n}</del>`), n = n.replace(new RegExp(Ce, "g"), "<br>"), n;
  }
  const e = t.children.map(ve).join(""), r = t;
  switch (r.type) {
    case "block-quote":
      return `<blockquote>${e}</blockquote>`;
    case "paragraph":
      return `<p>${e}</p>`;
    case "code":
      return `<pre><code>${e}</code></pre>`;
    case "bulleted-list":
      return `<ul>${e}</ul>`;
    case "numbered-list":
      return `<ol>${e}</ol>`;
    case "list-item":
      return `<li>${e}</li>`;
    case "heading-one":
      return `<h1>${e}</h1>`;
    case "heading-two":
      return `<h2>${e}</h2>`;
    case "heading-three":
      return `<h3>${e}</h3>`;
    case "heading-four":
      return `<h4>${e}</h4>`;
    case "heading-five":
      return `<h5>${e}</h5>`;
    case "link": {
      let o = "";
      if (r.url) {
        const l = gt(r.url);
        o = ` href="${Y(l)}"`;
      }
      let n = "";
      if (r.htmlAttributes && typeof r.htmlAttributes == "object")
        for (const [l, c] of Object.entries(r.htmlAttributes))
          l.toLowerCase().startsWith("on") || (n += ` ${Y(l)}="${Y(String(c))}"`);
      return `<a${o}${n}>${e}</a>`;
    }
    default:
      return e;
  }
}, ie = (t) => {
  if (!t || t.trim() === "")
    return O();
  try {
    if (t.includes("<p>") || t.includes("<h") || t.includes("<div>") || t.includes("<blockquote>") || t.includes("<ul>") || t.includes("<ol>")) {
      const r = new DOMParser().parseFromString(t, "text/html").body, o = Array.from(r.childNodes).map(Re).filter(Boolean);
      return Fe(o);
    } else
      return [
        {
          type: "paragraph",
          children: [{ text: t }]
        }
      ];
  } catch (e) {
    return console.warn("Failed to parse HTML:", e), O();
  }
}, Re = (t) => {
  if (t.nodeType === Node.TEXT_NODE)
    return (t.textContent || "").replace(/<br\s*\/?>/gi, Ce);
  if (t.nodeType !== Node.ELEMENT_NODE)
    return null;
  const e = t, r = e.tagName.toLowerCase(), o = Array.from(e.childNodes).map(Re).filter(Boolean);
  if (r in de) {
    const l = de[r], c = { type: l, children: [] };
    if (l === "link") {
      const u = e.getAttribute("href");
      u && (c.url = u);
      const h = {};
      Array.from(e.attributes).forEach((f) => {
        f.name !== "href" && !f.name.toLowerCase().startsWith("on") && (h[f.name] = f.value);
      }), Object.keys(h).length > 0 && (c.htmlAttributes = h);
    }
    return c.children = mt(o), c;
  }
  if (r in he) {
    const l = he[r];
    return { text: te(o), [l]: !0 };
  }
  return r === "span" ? { text: te(o) } : { text: te(o) };
}, mt = (t) => {
  const e = [];
  for (const r of t)
    typeof r == "string" ? r.trim() && e.push({ text: r }) : (r && j.isText(r) || r && _.isElement(r)) && e.push(r);
  return e.length === 0 && e.push({ text: "" }), e;
}, Ee = (t) => t.children.map((e) => j.isText(e) ? e.text : _.isElement(e) ? Ee(e) : "").join(""), te = (t) => t.filter(Boolean).map((e) => typeof e == "string" ? e : e && typeof e == "object" && "text" in e ? e.text : e && typeof e == "object" && "children" in e ? Ee(e) : String(e || "")).join(""), gt = (t) => {
  const e = String(t).trim().toLowerCase();
  return e.startsWith("javascript:") || e.startsWith("data:") || e.startsWith("vbscript:") ? "#" : String(t);
}, Fe = (t) => !Array.isArray(t) || t.length === 0 ? O() : t.map((e) => _.isElement(e) ? !e.children || e.children.length === 0 ? { ...e, children: [{ text: "" }] } : e : {
  type: "paragraph",
  children: [{ text: String(e) }]
}), fe = (t) => {
  try {
    const e = new URL(t);
    return e.protocol === "http:" || e.protocol === "https:";
  } catch {
    return !1;
  }
}, me = ["bulleted-list", "numbered-list"], yt = [
  "bold",
  "code",
  "italic",
  "underline",
  "superscript",
  "subscript",
  "strikethrough"
], W = (t) => yt.includes(t), bt = (t, e) => W(e) ? t[e] === !0 : !1, D = (t, e) => {
  const { selection: r } = t;
  if (!r || xe.isCollapsed(r)) {
    const o = b.marks(t);
    if (o && W(e))
      return o[e] === !0;
    if (!r && t.children.length > 0) {
      const n = t.children[0];
      if (n.children && n.children.length > 0) {
        const l = n.children[0];
        if (j.isText(l) && W(e))
          return l[e] === !0;
      }
    }
    return !1;
  }
  try {
    const o = Array.from(
      b.nodes(t, {
        at: r,
        match: (n) => j.isText(n)
      })
    );
    if (o.length === 0) {
      const n = b.marks(t);
      return !n || !W(e) ? !1 : n[e] === !0;
    }
    return o.every(([n]) => bt(n, e));
  } catch {
    const o = b.marks(t);
    return !o || !W(e) ? !1 : o[e] === !0;
  }
}, P = (t, e) => {
  const { selection: r } = t;
  if (r) {
    const [o] = Array.from(
      b.nodes(t, {
        at: b.unhangRange(t, r),
        match: (n) => !b.isEditor(n) && _.isElement(n) && n.type === e
      })
    );
    return !!o;
  }
  return t.children.length > 0 ? t.children[0].type === e : !1;
}, K = (t, e) => {
  D(t, e) ? b.removeMark(t, e) : b.addMark(t, e, !0);
}, re = (t, e) => {
  const r = P(t, e), o = me.includes(e);
  R.unwrapNodes(t, {
    match: (l) => !b.isEditor(l) && _.isElement(l) && me.includes(l.type),
    split: !0
  });
  let n;
  if (r ? n = { type: "paragraph" } : o ? n = { type: "list-item" } : n = { type: e }, R.setNodes(t, n), !r && o) {
    const l = { type: e, children: [] };
    R.wrapNodes(t, l);
  }
}, xt = (t) => {
  ne.focus(t);
}, St = (t, e) => {
  const r = ie(e);
  R.delete(t, {
    at: {
      anchor: b.start(t, []),
      focus: b.end(t, [])
    }
  }), R.insertNodes(t, r), R.select(t, b.start(t, []));
}, Tt = (t) => {
  const { insertData: e, insertText: r, isInline: o } = t;
  return t.isInline = (n) => n.type === "link" ? !0 : o(n), t.insertText = (n) => {
    n && fe(n) ? ge(t, n) : r(n);
  }, t.insertData = (n) => {
    const l = n.getData("text/plain");
    l && fe(l) ? ge(t, l) : e(n);
  }, t;
}, wt = (t) => {
  R.unwrapNodes(t, {
    match: (e) => !b.isEditor(e) && _.isElement(e) && e.type === "link"
  });
}, ge = (t, e) => {
  P(t, "link") && wt(t);
  const { selection: r } = t, o = r && xe.isCollapsed(r), n = {
    type: "link",
    url: e,
    children: o ? [{ text: e }] : []
  };
  o ? R.insertNodes(t, n) : (R.wrapNodes(t, n, { split: !0 }), R.collapse(t, { edge: "end" }));
}, kt = ({
  attributes: t,
  children: e,
  element: r
}) => {
  const o = r, n = { textAlign: o.align };
  switch (o.type) {
    case "block-quote":
      return /* @__PURE__ */ i("blockquote", { style: n, ...t, children: e });
    case "bulleted-list":
      return /* @__PURE__ */ i("ul", { style: n, ...t, children: e });
    case "heading-one":
      return /* @__PURE__ */ i("h1", { style: n, ...t, children: e });
    case "heading-two":
      return /* @__PURE__ */ i("h2", { style: n, ...t, children: e });
    case "heading-three":
      return /* @__PURE__ */ i("h3", { style: n, ...t, children: e });
    case "heading-four":
      return /* @__PURE__ */ i("h4", { style: n, ...t, children: e });
    case "heading-five":
      return /* @__PURE__ */ i("h5", { style: n, ...t, children: e });
    case "list-item":
      return /* @__PURE__ */ i("li", { style: n, ...t, children: e });
    case "numbered-list":
      return /* @__PURE__ */ i("ol", { style: n, ...t, children: e });
    case "link":
      return /* @__PURE__ */ i(
        "a",
        {
          ...t,
          href: o.url,
          rel: "noopener noreferrer",
          style: n,
          children: e
        }
      );
    default:
      return /* @__PURE__ */ i("p", { style: n, ...t, children: e });
  }
}, Ct = ({
  attributes: t,
  children: e,
  leaf: r
}) => {
  const o = r;
  return o.bold && (e = /* @__PURE__ */ i("strong", { children: e })), o.code && (e = /* @__PURE__ */ i("code", { children: e })), o.italic && (e = /* @__PURE__ */ i("em", { children: e })), o.underline && (e = /* @__PURE__ */ i("u", { children: e })), o.strikethrough && (e = /* @__PURE__ */ i("del", { children: e })), o.superscript && (e = /* @__PURE__ */ i("sup", { children: e })), o.subscript && (e = /* @__PURE__ */ i("sub", { children: e })), /* @__PURE__ */ i("span", { ...t, children: e });
}, vt = {
  placeholderCharacter: `​
`
}, Rt = ({
  withPreservedSelection: t
}) => {
  const e = Z(), r = I(() => {
    const c = [];
    return lt.forEach((u) => {
      D(e, u) && c.push(u);
    }), new Set(c);
  }, [e.selection, e.children, b.marks(e)]), o = I(() => {
    const c = [];
    return ct.forEach((u) => {
      D(e, u) && c.push(u);
    }), new Set(c);
  }, [e.selection, e.children, b.marks(e)]), n = I(() => /* @__PURE__ */ new Set([
    ...Array.from(r),
    ...Array.from(o)
  ]), [r, o]), l = E(
    (c) => {
      if (c === "all") return;
      const u = Array.from(c), h = Array.from(n), f = u.filter(
        (p) => !h.includes(p)
      ), T = h.filter(
        (p) => !u.includes(p)
      );
      [...f, ...T].forEach((p) => {
        p === "superscript" || p === "subscript" ? t(() => {
          const a = D(e, "superscript") ? "superscript" : D(e, "subscript") ? "subscript" : null;
          f.includes(p) && a && a !== p && K(e, a), K(e, p);
        })() : t(() => K(e, p))();
      });
    },
    [e, n, t]
  );
  return {
    selectedKeys: r,
    selectedScriptKeys: o,
    allSelectedKeys: n,
    handleAllSelectionChange: l
  };
}, Et = {
  bold: "Bold",
  bulletedList: "Bulleted list",
  code: "Code",
  headingFive: "Heading 5",
  headingFour: "Heading 4",
  headingOne: "Heading 1",
  headingThree: "Heading 3",
  headingTwo: "Heading 2",
  italic: "Italic",
  listFormatting: "List formatting",
  moreFormattingOptions: "More formatting options",
  moreStyles: "More styles",
  numberedList: "Numbered list",
  paragraph: "Paragraph",
  quote: "Quote",
  redo: "Redo",
  strikethrough: "Strikethrough",
  subscript: "Subscript",
  superscript: "Superscript",
  textFormatting: "Text formatting",
  textStyle: "Text style",
  textStyleMenu: "Text style menu",
  underline: "Underline",
  undo: "Undo"
}, Ft = {
  bold: "Fett",
  bulletedList: "Aufzählungsliste",
  code: "Code",
  headingFive: "Überschrift 5",
  headingFour: "Überschrift 4",
  headingOne: "Überschrift 1",
  headingThree: "Überschrift 3",
  headingTwo: "Überschrift 2",
  italic: "Kursiv",
  listFormatting: "Listenformatierung",
  moreFormattingOptions: "Weitere Formatierungsoptionen",
  moreStyles: "Weitere Stile",
  numberedList: "Nummerierte Liste",
  paragraph: "Paragraph",
  quote: "Zitat",
  redo: "Wiederherstellen",
  strikethrough: "Durchstreichen",
  subscript: "Tiefgestellt",
  superscript: "Hochgestellt",
  textFormatting: "Textformatierung",
  textStyle: "Textstil",
  textStyleMenu: "Textstilmenü",
  underline: "Unterstreichen",
  undo: "Rückgängig machen"
}, Mt = {
  bold: "Negrita",
  bulletedList: "Lista no numerada",
  code: "Código",
  headingFive: "Encabezamiento 5",
  headingFour: "Encabezamiento 4",
  headingOne: "Encabezamiento 1",
  headingThree: "Encabezamiento 3",
  headingTwo: "Encabezamiento 2",
  italic: "Cursiva",
  listFormatting: "Formatear lista",
  moreFormattingOptions: "Más opciones de formato",
  moreStyles: "Más estilos",
  numberedList: "Lista numerada",
  paragraph: "Párrafo",
  quote: "Presupuesto",
  redo: "Repetir",
  strikethrough: "Tachado",
  subscript: "Subíndice",
  superscript: "Índice superior",
  textFormatting: "Formatear texto",
  textStyle: "Estilo de texto",
  textStyleMenu: "Menú de estilo de texto",
  underline: "Subrayar",
  undo: "Deshacer"
}, It = {
  bold: "Gras",
  bulletedList: "Liste à puces",
  code: "Code",
  headingFive: "En-tête 5",
  headingFour: "En-tête 4",
  headingOne: "En-tête 1",
  headingThree: "En-tête 3",
  headingTwo: "En-tête 2",
  italic: "Italique",
  listFormatting: "Formatage de la liste",
  moreFormattingOptions: "Plus d'options de formatage",
  moreStyles: "Plus de styles",
  numberedList: "Liste numérotée",
  paragraph: "Paragraphe",
  quote: "Citation",
  redo: "Rétablir",
  strikethrough: "Barré",
  subscript: "Indice",
  superscript: "Exposant",
  textFormatting: "Formatage du texte",
  textStyle: "Style de texte",
  textStyleMenu: "Menu style de texte",
  underline: "Souligné",
  undo: "Annuler"
}, Lt = {
  bold: "Negrito",
  bulletedList: "Lista com marcadores",
  code: "Código",
  headingFive: "Cabeçalho 5",
  headingFour: "Cabeçalho 4",
  headingOne: "Cabeçalho 1",
  headingThree: "Cabeçalho 3",
  headingTwo: "Cabeçalho 2",
  italic: "Itálico",
  listFormatting: "Formatação de lista",
  moreFormattingOptions: "Mais opções de formatação",
  moreStyles: "Mais estilos",
  numberedList: "Lista numerada",
  paragraph: "Parágrafo",
  quote: "Cotação",
  redo: "Refazer",
  strikethrough: "Tachado",
  subscript: "Subscrito",
  superscript: "Sobrescrito",
  textFormatting: "Formatação de texto",
  textStyle: "Estilo de texto",
  textStyleMenu: "Menu de estilo de texto",
  underline: "Sublinhado",
  undo: "Desfazer"
}, Me = {
  en: /* @__PURE__ */ U(Et),
  de: /* @__PURE__ */ U(Ft),
  es: /* @__PURE__ */ U(Mt),
  "fr-FR": /* @__PURE__ */ U(It),
  "pt-BR": /* @__PURE__ */ U(Lt)
}, At = ({ isDisabled: t = !1 }) => {
  const e = Se(Me), r = Z(), o = ke(r), { allSelectedKeys: n, handleAllSelectionChange: l } = Rt({
    withPreservedSelection: o
  });
  return /* @__PURE__ */ d(
    v.Root,
    {
      selectionMode: "multiple",
      selectedKeys: n,
      onSelectionChange: l,
      children: [
        /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
          /* @__PURE__ */ i(v.Trigger, { asChild: !0, children: /* @__PURE__ */ i(
            oe,
            {
              size: "xs",
              variant: "ghost",
              "aria-label": e.format("moreFormattingOptions"),
              isDisabled: t,
              onMouseDown: (c) => c.preventDefault(),
              children: /* @__PURE__ */ i(We, {})
            }
          ) }),
          /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("moreStyles") })
        ] }),
        /* @__PURE__ */ d(v.Content, { children: [
          /* @__PURE__ */ i(v.Item, { id: "strikethrough", children: /* @__PURE__ */ d($, { slot: "label", display: "flex", alignItems: "center", gap: "200", children: [
            /* @__PURE__ */ i(je, {}),
            /* @__PURE__ */ i(A, { textStyle: "sm", children: e.format("strikethrough") })
          ] }) }),
          /* @__PURE__ */ i(v.Item, { id: "code", children: /* @__PURE__ */ d($, { slot: "label", display: "flex", alignItems: "center", gap: "200", children: [
            /* @__PURE__ */ i(Ge, {}),
            /* @__PURE__ */ i(A, { textStyle: "sm", children: e.format("code") })
          ] }) }),
          /* @__PURE__ */ i(v.Item, { id: "superscript", children: /* @__PURE__ */ d($, { slot: "label", display: "flex", alignItems: "center", gap: "200", children: [
            /* @__PURE__ */ i(A, { children: "X²" }),
            /* @__PURE__ */ i(A, { textStyle: "sm", children: e.format("superscript") })
          ] }) }),
          /* @__PURE__ */ i(v.Item, { id: "subscript", children: /* @__PURE__ */ d($, { slot: "label", display: "flex", alignItems: "center", gap: "200", children: [
            /* @__PURE__ */ i(A, { children: "X₂" }),
            /* @__PURE__ */ i(A, { textStyle: "sm", children: e.format("subscript") })
          ] }) })
        ] })
      ]
    }
  );
};
var C = {}, ye;
function Dt() {
  if (ye) return C;
  ye = 1, Object.defineProperty(C, "__esModule", {
    value: !0
  });
  for (var t = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform), e = {
    alt: "altKey",
    control: "ctrlKey",
    meta: "metaKey",
    shift: "shiftKey"
  }, r = {
    add: "+",
    break: "pause",
    cmd: "meta",
    command: "meta",
    ctl: "control",
    ctrl: "control",
    del: "delete",
    down: "arrowdown",
    esc: "escape",
    ins: "insert",
    left: "arrowleft",
    mod: t ? "meta" : "control",
    opt: "alt",
    option: "alt",
    return: "enter",
    right: "arrowright",
    space: " ",
    spacebar: " ",
    up: "arrowup",
    win: "meta",
    windows: "meta"
  }, o = {
    backspace: 8,
    tab: 9,
    enter: 13,
    shift: 16,
    control: 17,
    alt: 18,
    pause: 19,
    capslock: 20,
    escape: 27,
    " ": 32,
    pageup: 33,
    pagedown: 34,
    end: 35,
    home: 36,
    arrowleft: 37,
    arrowup: 38,
    arrowright: 39,
    arrowdown: 40,
    insert: 45,
    delete: 46,
    meta: 91,
    numlock: 144,
    scrolllock: 145,
    ";": 186,
    "=": 187,
    ",": 188,
    "-": 189,
    ".": 190,
    "/": 191,
    "`": 192,
    "[": 219,
    "\\": 220,
    "]": 221,
    "'": 222
  }, n = 1; n < 20; n++)
    o["f" + n] = 111 + n;
  function l(a, s, y) {
    s && !("byKey" in s) && (y = s, s = null), Array.isArray(a) || (a = [a]);
    var x = a.map(function(L) {
      return h(L, s);
    }), S = function(F) {
      return x.some(function(M) {
        return f(M, F);
      });
    }, H = y == null ? S : S(y);
    return H;
  }
  function c(a, s) {
    return l(a, s);
  }
  function u(a, s) {
    return l(a, { byKey: !0 }, s);
  }
  function h(a, s) {
    var y = s && s.byKey, x = {};
    a = a.replace("++", "+add");
    var S = a.split("+"), H = S.length;
    for (var L in e)
      x[e[L]] = !1;
    var F = !0, M = !1, m = void 0;
    try {
      for (var z = S[Symbol.iterator](), G; !(F = (G = z.next()).done); F = !0) {
        var k = G.value, J = k.endsWith("?") && k.length > 1;
        J && (k = k.slice(0, -1));
        var q = p(k), w = e[q];
        if (k.length > 1 && !w && !r[k] && !o[q])
          throw new TypeError('Unknown modifier: "' + k + '"');
        (H === 1 || !w) && (y ? x.key = q : x.which = T(k)), w && (x[w] = J ? null : !0);
      }
    } catch (N) {
      M = !0, m = N;
    } finally {
      try {
        !F && z.return && z.return();
      } finally {
        if (M)
          throw m;
      }
    }
    return x;
  }
  function f(a, s) {
    for (var y in a) {
      var x = a[y], S = void 0;
      if (x != null && (y === "key" && s.key != null ? S = s.key.toLowerCase() : y === "which" ? S = x === 91 && s.which === 93 ? 91 : s.which : S = s[y], !(S == null && x === !1) && S !== x))
        return !1;
    }
    return !0;
  }
  function T(a) {
    a = p(a);
    var s = o[a] || a.toUpperCase().charCodeAt(0);
    return s;
  }
  function p(a) {
    return a = a.toLowerCase(), a = r[a] || a, a;
  }
  return C.default = l, C.isHotkey = l, C.isCodeHotkey = c, C.isKeyHotkey = u, C.parseHotkey = h, C.compareHotkey = f, C.toKeyCode = T, C.toKeyName = p, C;
}
var Kt = /* @__PURE__ */ Dt();
const Ot = /* @__PURE__ */ Te(Kt), Ht = ({ editor: t }) => ({ handleKeyDown: E(
  (r) => {
    if ((r.metaKey || r.ctrlKey) && r.key === "z") {
      r.preventDefault(), r.shiftKey ? t.redo() : t.undo();
      return;
    }
    for (const o in ue)
      if (Ot(o, r)) {
        r.preventDefault();
        const n = ue[o];
        K(t, n);
        return;
      }
    if (r.shiftKey && r.key === "Enter") {
      r.preventDefault(), t.insertText(vt.placeholderCharacter);
      return;
    }
  },
  [t]
) }), Ie = function({
  ref: e,
  value: r,
  onChange: o,
  onFocus: n,
  onBlur: l,
  placeholder: c = X.placeholder,
  isDisabled: u = X.isDisabled,
  isReadOnly: h = X.isReadOnly,
  autoFocus: f = X.autoFocus,
  toolbar: T
  //...props
}) {
  const p = be(null), a = Ve(He(p, e)), s = I(() => {
    const m = ze();
    return Tt(Ue(_e(m)));
  }, []), { handleKeyDown: y } = Ht({ editor: s }), x = E(
    (m) => {
      n && n(m);
    },
    [n]
  ), S = E(
    (m) => {
      l && l(m);
    },
    [l]
  );
  De(
    a,
    () => ({
      focus: () => xt(s),
      resetValue: (m) => St(s, m)
    }),
    [s]
  );
  const H = E(
    (m) => /* @__PURE__ */ i(kt, { ...m }),
    []
  ), L = E(
    (m) => /* @__PURE__ */ i(Ct, { ...m }),
    []
  ), F = O(), M = Array.isArray(r) && r.length > 0 ? r : F;
  return /* @__PURE__ */ d(qe, { editor: s, value: M, onChange: o, children: [
    T && /* @__PURE__ */ i(st, { children: T }),
    /* @__PURE__ */ i(at, { asChild: !0, children: /* @__PURE__ */ i(
      Be,
      {
        renderElement: H,
        renderLeaf: L,
        placeholder: c,
        autoFocus: f,
        readOnly: h || u,
        onKeyDown: y,
        onFocus: x,
        onBlur: S,
        "aria-label": "Rich text editor",
        role: "textbox",
        "aria-multiline": "true"
      }
    ) })
  ] });
};
Ie.displayName = "RichTextEditor";
const Nt = ({
  withPreservedSelection: t,
  textStyles: e
}) => {
  const r = Z(), o = I(() => dt.find(
    (a) => P(r, a)
  ) || "paragraph", [r.selection, r.children]), n = e.find((a) => a.id === o), l = n?.label || "", c = E(
    (a) => {
      t(() => {
        re(r, a);
      })();
    },
    [r, t]
  ), u = E(
    (a) => {
      t(() => {
        const s = Array.from(a)[0], y = P(r, "bulleted-list") ? "bulleted-list" : P(r, "numbered-list") ? "numbered-list" : null;
        s ? re(r, s) : y && re(r, y);
      })();
    },
    [r, t]
  ), h = I(() => {
    const a = [];
    return D(r, "bold") && a.push("bold"), D(r, "italic") && a.push("italic"), D(r, "underline") && a.push("underline"), new Set(a);
  }, [r.selection, r.children, b.marks(r)]), f = I(() => {
    const a = [];
    return P(r, "bulleted-list") && a.push("bulleted-list"), P(r, "numbered-list") && a.push("numbered-list"), new Set(a);
  }, [r.selection, r.children]), T = I(() => r.history && r.history.undos.length > 0, [r.selection, r.children]), p = I(() => r.history && r.history.redos.length > 0, [r.selection, r.children]);
  return {
    currentTextStyle: o,
    selectedTextStyle: n,
    selectedTextStyleLabel: l,
    handleTextStyleChange: c,
    handleListToggle: u,
    selectedFormatKeys: h,
    selectedListKeys: f,
    hasUndos: T,
    hasRedos: p
  };
}, Le = ({
  isDisabled: t = !1
}) => {
  const e = Se(Me), r = Z(), o = ke(r), n = ut(e.format), {
    currentTextStyle: l,
    selectedTextStyleLabel: c,
    handleTextStyleChange: u,
    handleListToggle: h,
    selectedFormatKeys: f,
    selectedListKeys: T,
    hasUndos: p,
    hasRedos: a
  } = Nt({ withPreservedSelection: o, textStyles: n });
  return /* @__PURE__ */ d(
    nt,
    {
      orientation: "horizontal",
      "aria-label": e.format("textFormatting"),
      width: "full",
      overflow: "hidden",
      size: "xs",
      children: [
        /* @__PURE__ */ i(ae, { children: /* @__PURE__ */ d(
          v.Root,
          {
            onAction: (s) => u(String(s)),
            children: [
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ i(
                  v.Trigger,
                  {
                    height: "800",
                    width: "4000",
                    bg: "primary.1",
                    borderRadius: "200",
                    _hover: { bg: "primary.2" },
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    "aria-label": e.format("textStyleMenu"),
                    children: /* @__PURE__ */ d($, { display: "flex", alignItems: "center", gap: "200", px: "200", children: [
                      /* @__PURE__ */ i($, { display: "flex", alignItems: "center", gap: "200", flexGrow: "1", children: /* @__PURE__ */ i(A, { my: "auto", textStyle: "sm", fontWeight: "500", children: c }) }),
                      /* @__PURE__ */ i(Xe, {})
                    ] })
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("textStyle") })
              ] }),
              /* @__PURE__ */ i(v.Content, { children: n.map((s) => /* @__PURE__ */ i(
                v.Item,
                {
                  id: s.id,
                  ...l === s.id && {
                    "data-state": "checked"
                  },
                  children: /* @__PURE__ */ i(A, { ...s.props, children: s.label })
                },
                s.id
              )) })
            ]
          }
        ) }),
        /* @__PURE__ */ i(le, { orientation: "vertical" }),
        /* @__PURE__ */ d(
          ce.Root,
          {
            selectionMode: "multiple",
            selectedKeys: f,
            isDisabled: t,
            children: [
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ d(
                  B,
                  {
                    id: "bold",
                    size: "xs",
                    variant: "ghost",
                    "aria-label": e.format("bold"),
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    onPress: o(() => K(r, "bold")),
                    children: [
                      /* @__PURE__ */ i(Ye, {}),
                      /* @__PURE__ */ i(V, { children: e.format("bold") })
                    ]
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("bold") })
              ] }),
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ d(
                  B,
                  {
                    id: "italic",
                    size: "xs",
                    variant: "ghost",
                    "aria-label": e.format("italic"),
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    onPress: o(() => K(r, "italic")),
                    children: [
                      /* @__PURE__ */ i(Qe, {}),
                      /* @__PURE__ */ i(V, { children: e.format("italic") })
                    ]
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("italic") })
              ] }),
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ d(
                  B,
                  {
                    id: "underline",
                    size: "xs",
                    variant: "ghost",
                    "aria-label": e.format("underline"),
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    onPress: o(
                      () => K(r, "underline")
                    ),
                    children: [
                      /* @__PURE__ */ i(Ze, {}),
                      /* @__PURE__ */ i(V, { children: e.format("underline") })
                    ]
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("underline") })
              ] })
            ]
          }
        ),
        /* @__PURE__ */ i(At, { isDisabled: t }),
        /* @__PURE__ */ i(le, { orientation: "vertical" }),
        /* @__PURE__ */ d(
          ce.Root,
          {
            selectionMode: "single",
            selectedKeys: T,
            onSelectionChange: h,
            "aria-label": e.format("listFormatting"),
            isDisabled: t,
            children: [
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ i(
                  B,
                  {
                    id: "bulleted-list",
                    size: "xs",
                    variant: "ghost",
                    "aria-label": e.format("bulletedList"),
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    children: /* @__PURE__ */ i(Je, {})
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("bulletedList") })
              ] }),
              /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
                /* @__PURE__ */ i(
                  B,
                  {
                    id: "numbered-list",
                    size: "xs",
                    variant: "ghost",
                    "aria-label": e.format("numberedList"),
                    isDisabled: t,
                    onMouseDown: (s) => s.preventDefault(),
                    children: /* @__PURE__ */ i(et, {})
                  }
                ),
                /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("numberedList") })
              ] })
            ]
          }
        ),
        /* @__PURE__ */ i($, { flexGrow: "1" }),
        /* @__PURE__ */ d(ae, { children: [
          /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
            /* @__PURE__ */ d(
              oe,
              {
                size: "xs",
                variant: "ghost",
                "aria-label": e.format("undo"),
                isDisabled: !p || t,
                onPress: o(() => r.undo()),
                onMouseDown: (s) => s.preventDefault(),
                children: [
                  /* @__PURE__ */ i(tt, {}),
                  /* @__PURE__ */ i(V, { children: e.format("undo") })
                ]
              }
            ),
            /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("undo") })
          ] }),
          /* @__PURE__ */ d(g.Root, { delay: 0, closeDelay: 0, children: [
            /* @__PURE__ */ d(
              oe,
              {
                size: "xs",
                variant: "ghost",
                "aria-label": e.format("redo"),
                isDisabled: !a || t,
                onPress: o(() => r.redo()),
                onMouseDown: (s) => s.preventDefault(),
                children: [
                  /* @__PURE__ */ i(rt, {}),
                  /* @__PURE__ */ i(V, { children: e.format("redo") })
                ]
              }
            ),
            /* @__PURE__ */ i(g.Content, { placement: "top", children: e.format("redo") })
          ] })
        ] })
      ]
    }
  );
};
Le.displayName = "RichTextToolbar";
const Pt = (t) => {
  const {
    ref: e,
    value: r,
    defaultValue: o,
    onChange: n,
    onFocus: l,
    onBlur: c,
    placeholder: u = "",
    isDisabled: h = !1,
    isReadOnly: f = !1,
    isInvalid: T = !1,
    autoFocus: p = !1,
    ...a
  } = t, s = Ne({ recipe: $e }), [y, x] = s.splitVariantProps({
    // Only semantic variants go here (none currently defined)
    ...a
  }), [S, H] = Pe(x), L = {
    "data-disabled": h ? "true" : void 0,
    "data-invalid": T ? "true" : void 0,
    "data-readonly": f ? "true" : void 0
  }, [F, M] = se(() => {
    const w = r ?? o ?? "";
    try {
      return w ? ie(w) : O();
    } catch (N) {
      return console.warn("Failed to parse initial HTML, using empty value:", N), O();
    }
  }), [m, z] = se(() => r ?? o ?? ""), G = be(null);
  Ke(() => {
    if (r !== void 0 && r !== m) {
      const w = r ? ie(r) : O();
      M(w), z(r);
    }
  }, [r, m]);
  const k = E(
    (w) => {
      const N = ft(w), Ae = N !== m;
      M(w), z(N), Ae && n && n(N);
    },
    [m, n]
  ), q = Fe(F);
  return /* @__PURE__ */ i(
    it,
    {
      role: "group",
      ...y,
      ...S,
      ...H,
      ...L,
      ref: e,
      children: /* @__PURE__ */ i(
        Ie,
        {
          ref: G,
          value: q,
          onChange: k,
          onFocus: l,
          onBlur: c,
          placeholder: u,
          isDisabled: h,
          isReadOnly: f,
          autoFocus: p,
          toolbar: f ? null : /* @__PURE__ */ i(Le, { isDisabled: h })
        }
      )
    }
  );
};
Pt.displayName = "RichTextInput";
export {
  Pt as R,
  Te as g
};
//# sourceMappingURL=rich-text-input-Bo_zGUyj.es.js.map
