var g = Object.defineProperty;
var m = (e, s, r) => s in e ? g(e, s, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[s] = r;
var x = (e, s, r) => (m(e, typeof s != "symbol" ? s + "" : s, r), r);
import { an as E, j as t, ao as p, b2 as f, ab as N, x as b, z as j, $ as k } from "./index-c65ca4a4.mjs";
const S = function({ editorUrl: e, editorVersion: s }) {
  let r = "pending", o;
  const n = (async () => (window["@tryghost/koenig-lexical"] || await import(e.replace("{version}", s)), window["@tryghost/koenig-lexical"]))().then(
    (a) => {
      r = "success", o = a;
    },
    (a) => {
      r = "error", o = a;
    }
  );
  return { read: () => {
    switch (r) {
      case "pending":
        throw n;
      case "error":
        throw o;
      default:
        return o;
    }
  } };
};
class w extends E.Component {
  constructor() {
    super(...arguments);
    x(this, "state", {
      hasError: !1
    });
  }
  static getDerivedStateFromError() {
    return { hasError: !0 };
  }
  componentDidCatch(r, o) {
    console.error(r, o);
  }
  render() {
    return this.state.hasError ? /* @__PURE__ */ t.jsx("p", { className: "koenig-react-editor-error", children: "Loading has failed. Try refreshing the browser!" }) : this.props.children;
  }
}
const y = ({
  editor: e,
  value: s,
  onChange: r,
  onBlur: o,
  placeholder: l,
  nodes: n
}) => {
  const c = N((i) => {
    console.error(i);
  }, []), a = p(() => new Proxy({}, {
    get: (i, h) => e.read()[h]
  }), [e]), d = {
    DEFAULT_NODES: a.DEFAULT_TRANSFORMERS,
    BASIC_NODES: a.BASIC_TRANSFORMERS,
    MINIMAL_NODES: a.MINIMAL_TRANSFORMERS
  }, u = (i) => {
    i !== s && (r == null || r(i));
  };
  return /* @__PURE__ */ t.jsx(
    a.KoenigComposer,
    {
      nodes: a[n || "DEFAULT_NODES"],
      onError: c,
      children: /* @__PURE__ */ t.jsx(
        a.KoenigComposableEditor,
        {
          className: "koenig-lexical koenig-lexical-editor-input",
          darkMode: !1,
          isSnippetsEnabled: !1,
          markdownTransformers: d[n || "DEFAULT_NODES"],
          placeholderClassName: "koenig-lexical-editor-input-placeholder",
          placeholderText: l,
          singleParagraph: !0,
          onBlur: o,
          children: /* @__PURE__ */ t.jsx(a.HtmlOutputPlugin, { html: s, setHtml: u })
        }
      )
    }
  );
}, R = ({
  config: e,
  className: s,
  ...r
}) => {
  const o = p(() => S({
    editorUrl: e.editor.url,
    editorVersion: e.editor.version
  }), [e.editor.url, e.editor.version]);
  return /* @__PURE__ */ t.jsx("div", { className: s || "w-full", children: /* @__PURE__ */ t.jsx("div", { className: "koenig-react-editor w-full [&_*]:!font-inherit [&_*]:!text-inherit", children: /* @__PURE__ */ t.jsx(w, { children: /* @__PURE__ */ t.jsx(f, { fallback: /* @__PURE__ */ t.jsx("p", { className: "koenig-react-editor-loading", children: "Loading editor..." }), children: /* @__PURE__ */ t.jsx(y, { ...r, editor: o }) }) }) }) });
}, _ = ({
  title: e,
  hideTitle: s,
  error: r,
  hint: o,
  value: l,
  clearBg: n = !0,
  className: c = "",
  containerClassName: a = "",
  hintClassName: d = "",
  unstyled: u = !1,
  ...i
}) => {
  const h = u ? "" : b(
    "min-h-10 border-b py-2",
    n ? "bg-transparent" : "bg-grey-75 px-[10px]",
    r ? "border-red" : "border-grey-500 hover:border-grey-700 focus:border-black",
    e && !s && !n && "mt-2",
    c
  );
  return /* @__PURE__ */ t.jsxs("div", { className: `flex flex-col ${a}`, children: [
    e && /* @__PURE__ */ t.jsx(j, { className: s ? "sr-only" : "", grey: !0, useLabelTag: !0, children: e }),
    /* @__PURE__ */ t.jsx("div", { className: h, children: /* @__PURE__ */ t.jsx(R, { ...i, value: l }) }),
    o && /* @__PURE__ */ t.jsx(k, { className: d, color: r ? "red" : "", children: o })
  ] });
};
export {
  _ as H
};
//# sourceMappingURL=HtmlField-d23c9880.mjs.map
