import { defineComponent, ref, openBlock, createElementBlock, createElementVNode, normalizeClass, unref, createVNode, createBlock, createCommentVNode } from "vue";
import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
import "../../../adapter-vue.mjs";
import MessageInputEditor from "./message-input-editor.vue.mjs";
import MessageInputAt from "./message-input-at/index.vue.mjs";
import MessageInputButton from "./message-input-button.vue.mjs";
import MessageInputQuote from "./message-input-quote/index.vue.mjs";
import { sendTyping, sendMessages } from "../utils/sendMessage.mjs";
import { transformTextWithEmojiNamesToKeys } from "../emoji-config/index.mjs";
import { isPC, isH5 } from "../../../utils/env.mjs";
const _hoisted_1 = { class: "message-input-wrapper" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    placeholder: {
      type: String,
      default: "this is placeholder"
    },
    isMuted: {
      type: Boolean,
      default: true
    },
    muteText: {
      type: String,
      default: ""
    },
    enableInput: {
      type: Boolean,
      default: true
    },
    enableAt: {
      type: Boolean,
      default: true
    },
    enableDragUpload: {
      type: Boolean,
      default: true
    },
    enableTyping: {
      type: Boolean,
      default: true
    }
  },
  emits: ["sendMessage", "resetReplyOrReference", "onTyping"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const editor = ref();
    const messageInputAtRef = ref();
    const currentConversation = ref();
    TUIStore.watch(StoreName.CONV, {
      currentConversation: (conversation) => {
        currentConversation.value = conversation;
      }
    });
    const onTyping = (inputContentEmpty, inputBlur) => {
      sendTyping(inputContentEmpty, inputBlur);
    };
    const onAt = (show) => {
      var _a;
      (_a = messageInputAtRef.value) == null ? void 0 : _a.toggleAtList(show);
    };
    const sendMessage = async () => {
      var _a, _b;
      const _editorContentList = (_a = editor.value) == null ? void 0 : _a.getEditorContent();
      if (!_editorContentList || !currentConversation.value) return;
      const editorContentList = _editorContentList.map((editor2) => {
        if (editor2.type === "text") {
          editor2.payload.text = transformTextWithEmojiNamesToKeys(editor2.payload.text);
        }
        return editor2;
      });
      await sendMessages(
        editorContentList,
        currentConversation.value
      );
      emit("sendMessage");
      (_b = editor.value) == null ? void 0 : _b.resetEditor();
    };
    const insertEmoji = (emoji) => {
      var _a;
      (_a = editor.value) == null ? void 0 : _a.addEmoji(emoji);
    };
    const onAtListOpen = () => {
      var _a;
      if (isH5) {
        (_a = editor.value) == null ? void 0 : _a.blur();
      }
    };
    const insertAt = (atInfo) => {
      var _a, _b;
      ((_a = editor == null ? void 0 : editor.value) == null ? void 0 : _a.insertAt) && ((_b = editor == null ? void 0 : editor.value) == null ? void 0 : _b.insertAt(atInfo));
    };
    const reEdit = (content) => {
      var _a, _b;
      (_a = editor.value) == null ? void 0 : _a.resetEditor();
      (_b = editor.value) == null ? void 0 : _b.setEditorContent(content);
    };
    __expose({
      insertEmoji,
      reEdit
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", {
          class: normalizeClass(["message-input-container", !unref(isPC) && "message-input-container-h5"])
        }, [
          createVNode(MessageInputEditor, {
            ref_key: "editor",
            ref: editor,
            placeholder: props.placeholder,
            isMuted: props.isMuted,
            muteText: props.muteText,
            enableInput: props.enableInput,
            enableAt: props.enableAt,
            enableTyping: props.enableTyping,
            enableDragUpload: props.enableDragUpload,
            onSendMessage: sendMessage,
            onOnTyping: onTyping,
            onOnAt: onAt
          }, null, 8, ["placeholder", "isMuted", "muteText", "enableInput", "enableAt", "enableTyping", "enableDragUpload"]),
          !props.isMuted ? (openBlock(), createBlock(MessageInputButton, {
            key: 0,
            onSendMessage: sendMessage
          })) : createCommentVNode("", true),
          props.enableAt ? (openBlock(), createBlock(MessageInputAt, {
            key: 1,
            ref_key: "messageInputAtRef",
            ref: messageInputAtRef,
            onInsertAt: insertAt,
            onOnAtListOpen: onAtListOpen
          }, null, 512)) : createCommentVNode("", true)
        ], 2),
        createVNode(MessageInputQuote)
      ]);
    };
  }
});
export {
  _sfc_main as default
};
