import { ref, computed, mergeProps, unref, withCtx, createVNode, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderClass, ssrInterpolate, ssrRenderComponent } from 'vue/server-renderer';
import { useEditor, EditorContent } from '@tiptap/vue-3';
import StarterKit from '@tiptap/starter-kit';
import { z as useNuxtApp, D as VBtnToggle, b as VBtn } from './server.mjs';

const _sfc_main = {
  __name: "CoreEditor",
  __ssrInlineRender: true,
  props: {
    modelValue: { type: String, default: "" },
    label: { type: String, default: "" },
    hint: { type: String, default: "" },
    placeholder: { type: String, default: "" },
    height: { type: String, default: "" }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const { $prompt } = useNuxtApp();
    const props = __props;
    const emit = __emit;
    const editor = useEditor({
      content: props.modelValue || "",
      extensions: [StarterKit],
      onUpdate: ({ editor: editor2 }) => {
        emit("update:modelValue", editor2.getHTML());
      }
    });
    const focused = ref(false);
    const isLabelFloating = computed(() => {
      return focused.value || editor.value?.getText().trim().length > 0;
    });
    async function askLink() {
      const url = await $prompt("URL", "Insert Link", "", editor.value?.getAttributes("link").href || "");
      if (url === false) return;
      if (url) {
        editor.value?.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
      } else {
        editor.value?.chain().focus().unsetLink().run();
      }
    }
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<div${ssrRenderAttrs(mergeProps({
        class: ["v-editor", { focused: unref(focused) }]
      }, _attrs))}><label class="${ssrRenderClass({ float: unref(isLabelFloating) })}">${ssrInterpolate(__props.label)}</label><div class="editor-menu-bar menubar">`);
      _push(ssrRenderComponent(VBtnToggle, { density: "compact" }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-bold",
              variant: "text",
              active: unref(editor)?.isActive("bold"),
              onClick: ($event) => unref(editor).chain().focus().toggleBold().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-underline",
              variant: "text",
              active: unref(editor)?.isActive("underline"),
              onClick: ($event) => unref(editor).chain().focus().toggleUnderline().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-strikethrough",
              variant: "text",
              active: unref(editor)?.isActive("strike"),
              onClick: ($event) => unref(editor).chain().focus().toggleStrike().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-italic",
              variant: "text",
              active: unref(editor)?.isActive("italic"),
              onClick: ($event) => unref(editor).chain().focus().toggleItalic().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-header-1",
              active: unref(editor)?.isActive("heading", { level: 1 }),
              onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 1 }).run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-header-2",
              active: unref(editor)?.isActive("heading", { level: 2 }),
              onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 2 }).run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-header-3",
              active: unref(editor)?.isActive("heading", { level: 3 }),
              onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 3 }).run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-code-tags",
              active: unref(editor)?.isActive("code"),
              onClick: ($event) => unref(editor).chain().focus().toggleCode().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-quote-open",
              active: unref(editor)?.isActive("blockquote"),
              onClick: ($event) => unref(editor).chain().focus().toggleBlockquote().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-format-list-bulleted",
              active: unref(editor)?.isActive("bullet_list"),
              onClick: ($event) => unref(editor).chain().focus().toggleBulletList().run()
            }, null, _parent2, _scopeId));
            _push2(ssrRenderComponent(VBtn, {
              tabindex: "-1",
              icon: "mdi-link",
              active: unref(editor)?.isActive("link"),
              onClick: askLink
            }, null, _parent2, _scopeId));
          } else {
            return [
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-bold",
                variant: "text",
                active: unref(editor)?.isActive("bold"),
                onClick: ($event) => unref(editor).chain().focus().toggleBold().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-underline",
                variant: "text",
                active: unref(editor)?.isActive("underline"),
                onClick: ($event) => unref(editor).chain().focus().toggleUnderline().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-strikethrough",
                variant: "text",
                active: unref(editor)?.isActive("strike"),
                onClick: ($event) => unref(editor).chain().focus().toggleStrike().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-italic",
                variant: "text",
                active: unref(editor)?.isActive("italic"),
                onClick: ($event) => unref(editor).chain().focus().toggleItalic().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-header-1",
                active: unref(editor)?.isActive("heading", { level: 1 }),
                onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 1 }).run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-header-2",
                active: unref(editor)?.isActive("heading", { level: 2 }),
                onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 2 }).run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-header-3",
                active: unref(editor)?.isActive("heading", { level: 3 }),
                onClick: ($event) => unref(editor).chain().focus().toggleHeading({ level: 3 }).run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-code-tags",
                active: unref(editor)?.isActive("code"),
                onClick: ($event) => unref(editor).chain().focus().toggleCode().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-quote-open",
                active: unref(editor)?.isActive("blockquote"),
                onClick: ($event) => unref(editor).chain().focus().toggleBlockquote().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-format-list-bulleted",
                active: unref(editor)?.isActive("bullet_list"),
                onClick: ($event) => unref(editor).chain().focus().toggleBulletList().run()
              }, null, 8, ["active", "onClick"]),
              createVNode(VBtn, {
                tabindex: "-1",
                icon: "mdi-link",
                active: unref(editor)?.isActive("link"),
                onClick: askLink
              }, null, 8, ["active"])
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`</div>`);
      _push(ssrRenderComponent(unref(EditorContent), {
        editor: unref(editor),
        class: "v-editor__content",
        style: { height: __props.height },
        label: __props.label,
        "aria-label": __props.label
      }, null, _parent));
      _push(`</div>`);
    };
  }
};
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("components/Core/Editor.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};

export { _sfc_main as _ };
