"use client";
import { jsxs as a, jsx as t, Fragment as k } from "react/jsx-runtime";
import { Link as v } from "../../../../../node_modules/.pnpm/@tiptap_extension-link@2.23.0_@tiptap_core@2.23.0_@tiptap_pm@2.23.0__@tiptap_pm@2.23.0/node_modules/@tiptap/extension-link/dist/index.js";
import { Placeholder as y } from "../../../../../node_modules/.pnpm/@tiptap_extension-placeholder@2.23.0_@tiptap_core@2.23.0_@tiptap_pm@2.23.0__@tiptap_pm@2.23.0/node_modules/@tiptap/extension-placeholder/dist/index.js";
import { useEditor as N, EditorContent as w } from "../../../../../node_modules/.pnpm/@tiptap_react@2.23.0_@tiptap_core@2.23.0_@tiptap_pm@2.23.0__@tiptap_pm@2.23.0_react-dom@19.0._bpd46mhqzxhfdgzpwehtfd2mhm/node_modules/@tiptap/react/dist/index.js";
import { StarterKit as L } from "../../../../../node_modules/.pnpm/@tiptap_starter-kit@2.23.0/node_modules/@tiptap/starter-kit/dist/index.js";
import { useState as u, useEffect as A } from "react";
import { FaBold as C, FaItalic as j, FaStrikethrough as F, FaHeading as b, FaListUl as B, FaListOl as H, FaQuoteLeft as U, FaUnlink as E, FaLink as S } from "../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.0.0/node_modules/react-icons/fa/index.js";
import { classNames as s } from "../../utils/index.js";
const W = ({
  value: r,
  onChange: o,
  placeholder: p,
  className: f,
  ...x
}) => {
  const [l, i] = u(""), [g, c] = u(!1), e = N({
    extensions: [
      L,
      v.configure({
        openOnClick: !1
      }),
      y.configure({
        placeholder: p || "Write something..."
      })
    ],
    content: r,
    editorProps: {
      attributes: {
        class: "prose prose-slate prose-sm min-h-[150px] outline-none p-4"
      }
    },
    onUpdate: ({ editor: n }) => {
      const d = n.getHTML();
      o == null || o(d);
    },
    immediatelyRender: !1
  });
  A(() => {
    e && r !== void 0 && e.getHTML() !== r && e.commands.setContent(r);
  }, [e, r]);
  const m = () => {
    if (!l) return;
    const n = l.startsWith("http://") || l.startsWith("https://") ? l : `https://${l}`;
    e == null || e.chain().focus().extendMarkRange("link").setLink({ href: n }).run(), i(""), c(!1);
  }, h = (n) => {
    n.key === "Enter" && (n.preventDefault(), m());
  };
  return /* @__PURE__ */ a(
    "div",
    {
      className: s(
        "flex flex-col overflow-hidden rounded-md border border-slate-200",
        f
      ),
      children: [
        /* @__PURE__ */ a(
          "div",
          {
            className: s(
              "flex flex-wrap items-center border-b border-slate-200 bg-slate-50 p-2"
            ),
            children: [
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleBold().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("bold")
                    }
                  ),
                  type: "button",
                  title: "Bold",
                  children: /* @__PURE__ */ t(C, {})
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleItalic().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("italic")
                    }
                  ),
                  type: "button",
                  title: "Italic",
                  children: /* @__PURE__ */ t(j, {})
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleStrike().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("strike")
                    }
                  ),
                  type: "button",
                  title: "Strike",
                  children: /* @__PURE__ */ t(F, {})
                }
              ),
              /* @__PURE__ */ t("span", { className: s("mx-2 h-6 w-px bg-slate-200") }),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleHeading({ level: 1 }).run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("heading", { level: 1 })
                    }
                  ),
                  type: "button",
                  title: "Heading 1",
                  children: /* @__PURE__ */ t(b, { className: "text-lg" })
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleHeading({ level: 2 }).run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("heading", { level: 2 })
                    }
                  ),
                  type: "button",
                  title: "Heading 2",
                  children: /* @__PURE__ */ t(b, { className: "text-sm" })
                }
              ),
              /* @__PURE__ */ t("span", { className: s("mx-2 h-6 w-px bg-slate-200") }),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleBulletList().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("bulletList")
                    }
                  ),
                  type: "button",
                  title: "Bullet List",
                  children: /* @__PURE__ */ t(B, {})
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleOrderedList().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("orderedList")
                    }
                  ),
                  type: "button",
                  title: "Ordered List",
                  children: /* @__PURE__ */ t(H, {})
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => e == null ? void 0 : e.chain().focus().toggleBlockquote().run(),
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("blockquote")
                    }
                  ),
                  type: "button",
                  title: "Blockquote",
                  children: /* @__PURE__ */ t(U, {})
                }
              ),
              /* @__PURE__ */ t("span", { className: s("mx-2 h-6 w-px bg-slate-200") }),
              g ? /* @__PURE__ */ a("div", { className: s("mr-2 flex w-full flex-col gap-2"), children: [
                /* @__PURE__ */ t(
                  "input",
                  {
                    type: "text",
                    value: l,
                    onChange: (n) => i(n.target.value),
                    placeholder: "Enter URL",
                    onKeyDown: h,
                    className: s(
                      "placeholder:xs w-full rounded border border-slate-200 p-1 px-2 text-sm outline-none"
                    ),
                    autoFocus: !0
                  }
                ),
                /* @__PURE__ */ a("div", { className: s("flex gap-1"), children: [
                  /* @__PURE__ */ t(
                    "button",
                    {
                      onClick: m,
                      className: s(
                        "text-whit mr-1 cursor-pointer rounded bg-slate-800 p-1 px-2 text-xs hover:bg-slate-900 focus:bg-slate-900"
                      ),
                      children: "Apply"
                    }
                  ),
                  /* @__PURE__ */ t(
                    "button",
                    {
                      onClick: () => {
                        i(""), c(!1);
                      },
                      className: s(
                        "mr-1 cursor-pointer rounded border border-slate-200 bg-slate-100 p-1 px-2 text-xs hover:bg-slate-200"
                      ),
                      children: "Cancel"
                    }
                  )
                ] })
              ] }) : /* @__PURE__ */ t(k, { children: /* @__PURE__ */ t(
                "button",
                {
                  onClick: () => {
                    e != null && e.isActive("link") ? e.chain().focus().unsetLink().run() : c(!0);
                  },
                  className: s(
                    "mb-1 mr-1 flex h-8 w-8 cursor-pointer items-center justify-center rounded border-none bg-transparent p-2 text-sm text-slate-600 hover:bg-slate-200",
                    {
                      "bg-slate-200 font-medium text-slate-800": e == null ? void 0 : e.isActive("link")
                    }
                  ),
                  type: "button",
                  title: e != null && e.isActive("link") ? "Unlink" : "Link",
                  children: e != null && e.isActive("link") ? /* @__PURE__ */ t(E, {}) : /* @__PURE__ */ t(S, {})
                }
              ) }),
              /* @__PURE__ */ t("span", { className: s("mx-2 h-6 w-px bg-slate-200") })
            ]
          }
        ),
        /* @__PURE__ */ t(w, { editor: e, ...x })
      ]
    }
  );
};
export {
  W as TextEditor
};
//# sourceMappingURL=text-editor.js.map
