"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const TUIChatEngine = require("@tencentcloud/chat-uikit-engine");
const universalApi = require("@tencentcloud/universal-api");
require("../../../../adapter-vue.js");
const Icon = require("../../../common/Icon.vue.js");
const index = require("../../../common/Toast/index.js");
const msgDel = require("../../../../assets/icon/msg-del.svg.js");
const msgCopy = require("../../../../assets/icon/msg-copy.svg.js");
const msgQuote = require("../../../../assets/icon/msg-quote.svg.js");
const msgRevoke = require("../../../../assets/icon/msg-revoke.svg.js");
const msgForward = require("../../../../assets/icon/msg-forward.svg.js");
const translate = require("../../../../assets/icon/translate.svg.js");
const multipleSelect = require("../../../../assets/icon/multiple-select.svg.js");
const convertText_zh = require("../../../../assets/icon/convertText_zh.svg.js");
const enableSampleTaskStatus = require("../../../../utils/enableSampleTaskStatus.js");
const index$1 = require("../../emoji-config/index.js");
const env = require("../../../../utils/env.js");
const config = require("../../config.js");
const copy = require("../../utils/copy.js");
const type = require("../../../common/Toast/type.js");
const _hoisted_1 = ["onClick", "onMousedown"];
const _hoisted_2 = { class: "list-item-text" };
const _sfc_main = /* @__PURE__ */ Vue.defineComponent({
  __name: "index",
  props: {
    messageItem: { default: () => ({}) },
    isMultipleSelectMode: { type: Boolean, default: false }
  },
  emits: ["toggleMultipleSelectMode"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const emits = __emit;
    const props = __props;
    const featureConfig = config.default.getFeatureConfig();
    const TYPES = TUIChatEngine.TYPES;
    const actionItems = Vue.ref([
      {
        key: "open",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.打开"),
        iconUrl: msgCopy.default,
        renderCondition() {
          var _a;
          if (!featureConfig.DownloadFile || !message.value) return false;
          return env.isPC && (((_a = message.value) == null ? void 0 : _a.type) === TYPES.MSG_FILE || message.value.type === TYPES.MSG_VIDEO || message.value.type === TYPES.MSG_IMAGE);
        },
        clickEvent: openMessage
      },
      {
        key: "copy",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.复制"),
        iconUrl: msgCopy.default,
        renderCondition() {
          if (!featureConfig.CopyMessage || !message.value) return false;
          return message.value.type === TYPES.MSG_TEXT;
        },
        clickEvent: copyMessage
      },
      {
        key: "revoke",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.撤回"),
        iconUrl: msgRevoke.default,
        renderCondition() {
          if (!featureConfig.RevokeMessage || !message.value) return false;
          return message.value.flow === "out" && message.value.status === "success";
        },
        clickEvent: revokeMessage
      },
      {
        key: "delete",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.删除"),
        iconUrl: msgDel.default,
        renderCondition() {
          if (!featureConfig.DeleteMessage || !message.value) return false;
          return message.value.status === "success";
        },
        clickEvent: deleteMessage
      },
      {
        key: "forward",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.转发"),
        iconUrl: msgForward.default,
        renderCondition() {
          if (!featureConfig.ForwardMessage || !message.value) return false;
          return message.value.status === "success";
        },
        clickEvent: forwardSingleMessage
      },
      {
        key: "quote",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.引用"),
        iconUrl: msgQuote.default,
        renderCondition() {
          if (!featureConfig.QuoteMessage || !message.value) return false;
          const _message = TUIChatEngine.TUIStore.getMessageModel(message.value.ID);
          return message.value.status === "success" && !_message.getSignalingInfo();
        },
        clickEvent: quoteMessage
      },
      {
        key: "translate",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.翻译"),
        visible: false,
        iconUrl: translate.default,
        renderCondition() {
          if (!featureConfig.TranslateMessage || !message.value) return false;
          return message.value.status === "success" && message.value.type === TYPES.MSG_TEXT;
        },
        clickEvent: translateMessage
      },
      {
        key: "convert",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.转文字"),
        visible: false,
        iconUrl: convertText_zh.default,
        renderCondition() {
          if (!featureConfig.VoiceToText || !message.value) return false;
          return message.value.status === "success" && message.value.type === TYPES.MSG_AUDIO;
        },
        clickEvent: convertVoiceToText
      },
      {
        key: "multi-select",
        text: TUIChatEngine.TUITranslateService.t("TUIChat.多选"),
        iconUrl: multipleSelect.default,
        renderCondition() {
          if (!featureConfig.MultiSelection || !message.value) return false;
          return message.value.status === "success";
        },
        clickEvent: multipleSelectMessage
      }
    ]);
    const message = Vue.ref();
    const messageToolDom = Vue.ref();
    Vue.onMounted(() => {
      TUIChatEngine.TUIStore.watch(TUIChatEngine.StoreName.CHAT, {
        translateTextInfo: onMessageTranslationInfoUpdated,
        voiceToTextInfo: onMessageConvertInfoUpdated
      });
    });
    Vue.onUnmounted(() => {
      TUIChatEngine.TUIStore.unwatch(TUIChatEngine.StoreName.CHAT, {
        translateTextInfo: onMessageTranslationInfoUpdated,
        voiceToTextInfo: onMessageConvertInfoUpdated
      });
    });
    Vue.watchEffect(() => {
      message.value = TUIChatEngine.TUIStore.getMessageModel(props.messageItem.ID);
    });
    const isAllActionItemInvalid = Vue.computed(() => {
      for (let i = 0; i < actionItems.value.length; ++i) {
        if (actionItems.value[i].renderCondition()) {
          return false;
        }
      }
      return true;
    });
    function getFunction(index2) {
      actionItems.value[index2].clickEvent();
    }
    function openMessage() {
      var _a;
      let url = "";
      switch ((_a = message.value) == null ? void 0 : _a.type) {
        case TUIChatEngine.TYPES.MSG_FILE:
          url = message.value.payload.fileUrl;
          break;
        case TUIChatEngine.TYPES.MSG_VIDEO:
          url = message.value.payload.remoteVideoUrl;
          break;
        case TUIChatEngine.TYPES.MSG_IMAGE:
          url = message.value.payload.imageInfoArray[0].url;
          break;
      }
      window == null ? void 0 : window.open(url, "_blank");
    }
    function revokeMessage() {
      if (!message.value) return;
      const messageModel = TUIChatEngine.TUIStore.getMessageModel(message.value.ID);
      messageModel.revokeMessage().then(() => {
        enableSampleTaskStatus.enableSampleTaskStatus("revokeMessage");
      }).catch((error) => {
        if (error.code === 20016) {
          const message2 = TUIChatEngine.TUITranslateService.t("TUIChat.已过撤回时限");
          index.Toast({
            message: message2,
            type: type.default.ERROR
          });
        }
      });
    }
    function deleteMessage() {
      if (!message.value) return;
      const messageModel = TUIChatEngine.TUIStore.getMessageModel(message.value.ID);
      messageModel.deleteMessage();
    }
    async function copyMessage() {
      var _a, _b, _c, _d, _e;
      if (env.isUniFrameWork) {
        (_c = universalApi.TUIGlobal) == null ? void 0 : _c.setClipboardData({
          data: index$1.transformTextWithKeysToEmojiNames((_b = (_a = message.value) == null ? void 0 : _a.payload) == null ? void 0 : _b.text)
        });
      } else {
        copy.default.copySelection((_e = (_d = message.value) == null ? void 0 : _d.payload) == null ? void 0 : _e.text);
      }
    }
    function beforeCopy(key) {
      if (key !== "copy" || env.isH5) {
        return;
      }
      copy.default.saveCurrentSelection();
    }
    function forwardSingleMessage() {
      if (!message.value) return;
      TUIChatEngine.TUIStore.update(TUIChatEngine.StoreName.CUSTOM, "singleForwardMessageID", message.value.ID);
    }
    function quoteMessage() {
      if (!message.value) return;
      message.value.quoteMessage();
    }
    function translateMessage() {
      const enable = TUIChatEngine.TUIStore.getData(TUIChatEngine.StoreName.APP, "enabledTranslationPlugin");
      if (!enable) {
        index.Toast({
          message: TUIChatEngine.TUITranslateService.t("TUIChat.请开通翻译功能"),
          type: type.default.WARNING
        });
        return;
      }
      if (!message.value) return;
      const index$12 = actionItems.value.findIndex((item) => item.key === "translate");
      TUIChatEngine.TUIStore.update(TUIChatEngine.StoreName.CHAT, "translateTextInfo", {
        conversationID: message.value.conversationID,
        messageID: message.value.ID,
        visible: !actionItems.value[index$12].visible
      });
    }
    function convertVoiceToText() {
      const enable = TUIChatEngine.TUIStore.getData(TUIChatEngine.StoreName.APP, "enabledVoiceToText");
      if (!enable) {
        index.Toast({
          message: TUIChatEngine.TUITranslateService.t("TUIChat.请开通语音转文字功能")
        });
        return;
      }
      if (!message.value) return;
      const index$12 = actionItems.value.findIndex((item) => item.key === "convert");
      TUIChatEngine.TUIStore.update(TUIChatEngine.StoreName.CHAT, "voiceToTextInfo", {
        conversationID: message.value.conversationID,
        messageID: message.value.ID,
        visible: !actionItems.value[index$12].visible
      });
    }
    function multipleSelectMessage() {
      emits("toggleMultipleSelectMode");
    }
    function onMessageTranslationInfoUpdated(info) {
      if (info === void 0) return;
      const translationInfoList = info.get(props.messageItem.conversationID) || [];
      const idx = actionItems.value.findIndex((item) => item.key === "translate");
      for (let i = 0; i < translationInfoList.length; ++i) {
        const { messageID, visible } = translationInfoList[i];
        if (messageID === props.messageItem.ID) {
          actionItems.value[idx].text = TUIChatEngine.TUITranslateService.t(visible ? "TUIChat.隐藏" : "TUIChat.翻译");
          actionItems.value[idx].visible = !!visible;
          return;
        }
      }
      actionItems.value[idx].text = TUIChatEngine.TUITranslateService.t("TUIChat.翻译");
    }
    function onMessageConvertInfoUpdated(info) {
      if (info === void 0) return;
      const convertInfoList = info.get(props.messageItem.conversationID) || [];
      const idx = actionItems.value.findIndex((item) => item.key === "convert");
      for (let i = 0; i < convertInfoList.length; ++i) {
        const { messageID, visible } = convertInfoList[i];
        if (messageID === props.messageItem.ID) {
          actionItems.value[idx].text = TUIChatEngine.TUITranslateService.t(visible ? "TUIChat.隐藏" : "TUIChat.转文字");
          actionItems.value[idx].visible = !!visible;
          return;
        }
      }
      actionItems.value[idx].text = TUIChatEngine.TUITranslateService.t("TUIChat.转文字");
    }
    __expose({
      messageToolDom
    });
    return (_ctx, _cache) => {
      return !Vue.unref(isAllActionItemInvalid) && !_ctx.messageItem.hasRiskContent ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 0,
        ref_key: "messageToolDom",
        ref: messageToolDom,
        class: Vue.normalizeClass(["dialog-item", !Vue.unref(env.isPC) ? "dialog-item-h5" : "dialog-item-web"])
      }, [
        Vue.unref(featureConfig).EmojiReaction ? Vue.renderSlot(_ctx.$slots, "TUIEmojiPlugin", { key: 0 }, void 0, true) : Vue.createCommentVNode("", true),
        Vue.createElementVNode("div", {
          class: Vue.normalizeClass(["dialog-item-list", !Vue.unref(env.isPC) ? "dialog-item-list-h5" : "dialog-item-list-web"])
        }, [
          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(actionItems), (item, index2) => {
            return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
              item.renderCondition() ? (Vue.openBlock(), Vue.createElementBlock("div", {
                key: item.key,
                class: "list-item",
                onClick: ($event) => getFunction(index2),
                onMousedown: ($event) => beforeCopy(item.key)
              }, [
                Vue.createVNode(Icon.default, {
                  file: item.iconUrl,
                  size: "15px"
                }, null, 8, ["file"]),
                Vue.createElementVNode("span", _hoisted_2, Vue.toDisplayString(item.text), 1)
              ], 40, _hoisted_1)) : Vue.createCommentVNode("", true)
            ], 64);
          }), 256))
        ], 2)
      ], 2)) : Vue.createCommentVNode("", true);
    };
  }
});
exports.default = _sfc_main;
