import { aC as w, a4 as t, a3 as R, ab as A, V as $, w as f, X as k, dr as M, a5 as j, ll as J, ci as Q, U as _, H as u, ad as b, I as C, ae as g, af as x, et as I, co as U, am as S, ag as X, dJ as K, ah as G, aj as m, ai as L, aH as Y, cX as Z } from "./56c67d3b.js";
import ee, { useRef as l, useCallback as y, useEffect as v, useContext as V, useState as H, Suspense as te } from "react";
import "react-dom";
function oe(e, o) {
  o === void 0 && (o = 0);
  var r = l(!1), a = l(), n = l(e), h = y(function() {
    return r.current;
  }, []), c = y(function() {
    r.current = !1, a.current && clearTimeout(a.current), a.current = setTimeout(function() {
      r.current = !0, n.current();
    }, o);
  }, [o]), d = y(function() {
    r.current = null, a.current && clearTimeout(a.current);
  }, []);
  return v(function() {
    n.current = e;
  }, [e]), v(function() {
    return c(), d;
  }, [o]), [h, d, c];
}
function re(e, o, r) {
  o === void 0 && (o = 0), r === void 0 && (r = []);
  var a = oe(e, o), n = a[0], h = a[1], c = a[2];
  return v(c, r), [n, h];
}
const B = w`
  & .ql-snow {
    .ql-picker.ql-header {
      .ql-picker-label::before,
      .ql-picker-item::before {
        content: "${t("richTextEditor.content")}";
      }

      .ql-picker-label[data-value="1"]::before,
      .ql-picker-item[data-value="1"]::before {
        content: "${t("richTextEditor.title")} 1";
      }

      .ql-picker-label[data-value="2"]::before,
      .ql-picker-item[data-value="2"]::before {
        content: "${t("richTextEditor.title")} 2";
      }

      .ql-picker-label[data-value="3"]::before,
      .ql-picker-item[data-value="3"]::before {
        content: "${t("richTextEditor.title")} 3";
      }

      .ql-picker-item[data-value="1"]::before {
        font-size: 26px;
      }

      .ql-picker-item[data-value="3"]::before {
        font-size: 19px;
      }

      .ql-picker-item[data-value="3"]::before {
        font-size: 15px;
      }
    }
    & .ql-tooltip.ql-editing a.ql-action::after {
      content: "${t("richTextEditor.save")}";
    }
    & .ql-tooltip::before {
      content: "${t("richTextEditor.link")}";
    }
    & .ql-tooltip {
      a.ql-action::after {
        content: "${t("richTextEditor.edit")}";
      }
      a.ql-remove::before {
        content: "${t("richTextEditor.remove")}";
      }
    }
  }
`, O = (e, o) => w`
  height: 100%;

  .ql-editor::-webkit-scrollbar {
    display: ${o ? "block" : "none"};
  }

  & .ql-editor {
    min-height: 85px;
  }
  & .ql-snow .ql-tooltip.ql-editing {
    input[type="text"] {
      width: 130px;
    }
  }
  & .ql-snow {
    &.ql-container,
    &.ql-toolbar {
      border-color: ${e.border};
      background: ${e.background};
      
    }
  }
  & .ql-toolbar {
    border-radius: ${e.radius} ${e.radius} 0 0;
    border-width: ${e.borderWidth ? e.borderWidth : "1px"};
  }
  & .ql-container {
    border-radius: 0 0 ${e.radius} ${e.radius};
    background: ${e.background};
    border-width: ${e.borderWidth ? e.borderWidth : "1px"};
  }
`, D = (e) => w`
  .ql-snow.ql-toolbar {
    height: 0;
    overflow: hidden;
    padding: 0;
    border-bottom: 0;
    border: none;
  }
  .quill .ql-snow.ql-container {
    border-radius: ${e.radius};
    border: 1px solid ${e.border};
  }
`, ae = R.div`
  ${B}
  ${(e) => O(e.$style, e.$contentScrollBar)}
  & .ql-container .ql-editor {
    min-height: 125px;
  }
  ${(e) => e.$hideToolbar ? D(e.$style) : ""};
`, ie = R.div`
  ${B}
  ${(e) => O(e.$style, e.$contentScrollBar)}
  & .quill {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  & .ql-snow {
    &.ql-container {
      flex: 1;
      overflow: auto;
    }
  }
  ${(e) => e.$hideToolbar ? D(e.$style) : ""};
`, le = [[{
  header: [1, 2, 3, !1]
}], ["bold", "italic", "underline", "strike", "blockquote"], [{
  list: "ordered"
}, {
  list: "bullet"
}], [{
  indent: "-1"
}, {
  indent: "+1"
}], [{
  color: []
}, {
  background: []
}, {
  align: []
}], ["link", "image"], ["clean"]], ne = {
  value: A("value"),
  hideToolbar: $,
  readOnly: $,
  autoHeight: f(Y, "fixed"),
  contentScrollBar: f($, !1),
  placeholder: f(k, t("richTextEditor.placeholder")),
  toolbar: f(k, JSON.stringify(le)),
  onEvent: M,
  style: j(J, "style"),
  ...Q
}, ce = ee.lazy(() => import("./7ae7af61.js").then((e) => e.i));
function de(e) {
  const [o, r] = H(0), [a, n] = H(""), h = l(null), c = l(null);
  l(0);
  const d = l(e.onChange);
  d.current = e.onChange;
  const P = l((i) => {
    var s;
    return (s = d.current) == null ? void 0 : s.call(d, i);
  });
  re(() => {
    r(Math.random());
  }, 500, [e.placeholder]);
  const N = (i, s) => {
    try {
      s.parentNode;
    } catch {
      return !1;
    }
    return i.contains(s);
  }, W = (i) => {
    n(i), P.current(i);
  };
  v(() => {
    let i = e.value;
    /^<\w+>.+<\/\w+>$/.test(e.value) || (i = `<p class="">${e.value}</p>`), n(i);
  }, [e.value]);
  const z = (i) => {
    var q, p;
    (p = ((q = c.current) == null ? void 0 : q.editor).theme.pickers) == null || p.forEach((E) => {
      N(E.container, i.nativeEvent.target) || E.close();
    });
  }, T = "rtf-editor", F = e.autoHeight ? ae : ie;
  return /* @__PURE__ */ u(F, {
    id: T,
    onClick: z,
    ref: h,
    $hideToolbar: e.hideToolbar,
    $style: e.$style,
    $contentScrollBar: e.contentScrollBar,
    children: /* @__PURE__ */ u(te, {
      fallback: /* @__PURE__ */ u(Z, {}),
      children: /* @__PURE__ */ u(ce, {
        ref: c,
        bounds: `#${T}`,
        modules: {
          toolbar: JSON.parse(e.toolbar)
        },
        theme: "snow",
        value: a,
        placeholder: e.placeholder,
        readOnly: e.readOnly,
        onChange: W
      }, o)
    })
  });
}
const ue = new _(ne, (e) => {
  const o = (r) => {
    e.value.onChange(r), e.onEvent("change");
  };
  return /* @__PURE__ */ u(de, {
    autoHeight: e.autoHeight,
    hideToolbar: e.hideToolbar,
    toolbar: e.toolbar,
    readOnly: e.readOnly,
    value: e.value.value,
    placeholder: e.placeholder,
    onChange: o,
    $style: e.style,
    contentScrollBar: e.contentScrollBar
  });
}).setPropertyViewFn((e) => /* @__PURE__ */ b(C, {
  children: [/* @__PURE__ */ b(g, {
    name: x.basic,
    children: [e.value.propertyView({
      label: t("richTextEditor.defaultValue")
    }), I(e)]
  }), /* @__PURE__ */ u(U, {
    ...e
  }), ["logic", "both"].includes(V(S).editorModeStatus) && /* @__PURE__ */ b(g, {
    name: x.interaction,
    children: [e.onEvent.getPropertyView(), X(e), K(e)]
  }), ["layout", "both"].includes(V(S).editorModeStatus) && /* @__PURE__ */ b(C, {
    children: [/* @__PURE__ */ b(g, {
      name: x.layout,
      children: [e.autoHeight.getPropertyView(), !e.autoHeight.getView() && e.contentScrollBar.propertyView({
        label: t("prop.textAreaScrollBar")
      }), e.toolbar.propertyView({
        label: t("richTextEditor.toolbar"),
        tooltip: t("richTextEditor.toolbarDescription")
      }), e.hideToolbar.propertyView({
        label: t("richTextEditor.hideToolbar")
      })]
    }), /* @__PURE__ */ u(g, {
      name: x.style,
      children: e.style.getPropertyView()
    })]
  })]
})).build();
class se extends ue {
  autoHeight() {
    return this.children.autoHeight.getView();
  }
}
const ge = G(se, [new m("value", t("export.richTextEditorValueDesc")), new m("readOnly", t("export.richTextEditorReadOnlyDesc")), new m("hideToolbar", t("export.richTextEditorHideToolBarDesc")), L]);
export {
  ge as RichTextEditorComp
};
