import { j as e } from "../../../../../_virtual/jsx-runtime.js";
import { useDraftHelpers as d } from "../../../../../use-page-data.js";
import m, { DatasourceItemButton as p } from "../../shared/components/TextEditor.js";
import { useRef as x } from "react";
import { tx as a, css as u } from "../../../../style-system/dist/twind.js";
import { useDebounceCallback as f } from "../../../../../node_modules/.pnpm/usehooks-ts@3.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/usehooks-ts/dist/index.js";
import "../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import "../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@18.3.0-canary-3d9b20132-20240124_react@18.3.0-canary-3d_c02c1e17bf76c343fd22d1f22394ecf5/node_modules/react-hot-toast/dist/index.js";
import { RiBracesLine as g } from "../../../../../node_modules/.pnpm/react-icons@5.3.0_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-icons/ri/index.js";
import { insertInEditor as h, getEditorNodeFromField as j } from "../../shared/utils/editor-utils.js";
import { IconButton as B } from "../../../../../node_modules/.pnpm/@radix-ui_themes@3.1.4_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@18.3.3_46b1dabc193c5ff5696ee783983c694e/node_modules/@radix-ui/themes/dist/esm/components/icon-button.js";
function R(i, r, t = !1, s = !0) {
  const n = d();
  if (s)
    return (o) => {
      console.log("Updating text editor props", i, r), t ? n.updateBrickProps(i, {
        [r]: o.editor.getText()
      }) : n.updateBrickProps(i, { [r]: o.editor.getHTML() });
    };
}
function k({
  currentValue: i,
  brickId: r,
  schema: t,
  onChange: s,
  placeholder: n
}) {
  const o = x(null), c = f(s, 300);
  return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    /* @__PURE__ */ e.jsx(
      "div",
      {
        className: a(
          "rounded border border-gray-300 px-2 py-[4px] text-sm flex-grow max-w-[calc(100%-34px)] bg-white",
          u({
            "&:has([contenteditable='true']:focus)": {
              outline: "1px solid var(--violet-8)",
              borderColor: "var(--violet-8)"
            }
          })
        ),
        children: /* @__PURE__ */ e.jsx(
          m,
          {
            content: i,
            brickId: r,
            ref: o,
            className: a(
              u({ lineHeight: "1.5" }),
              t["ui:multiline"] && `scrollbar-thin ${t["ui:textarea-class"] ?? "min-h-24"}`
            ),
            placeholder: t["ui:placeholder"] ?? n,
            spellCheck: !!t["ui:spellcheck"],
            singleline: !0,
            noMenuBar: !0,
            dynamic: !0,
            onChange: (l) => {
              c(l.editor.getText());
            }
          }
        )
      }
    ),
    /* @__PURE__ */ e.jsx(
      p,
      {
        brickId: r,
        onFieldClick: (l) => {
          o.current?.editor && h(o.current.editor, j(l));
        },
        children: /* @__PURE__ */ e.jsx(B, { variant: "surface", radius: "large", className: "!w-[31px] !h-[31px]", children: /* @__PURE__ */ e.jsx(g, { className: "w-4 h-4" }) })
      }
    )
  ] });
}
export {
  k as useDynamicTextEditor,
  R as useTextEditorUpdateHandler
};
//# sourceMappingURL=use-editable-text.js.map
