"use strict";
const common_vendor = require("../../../../../common/vendor.js");
require("../../../../adapter-vue.js");
const TUIKit_components_common_Toast_index = require("../../../common/Toast/index.js");
const common_assets = require("../../../../../common/assets.js");
const TUIKit_utils_enableSampleTaskStatus = require("../../../../utils/enableSampleTaskStatus.js");
const TUIKit_components_TUIChat_emojiConfig_index = require("../../emoji-config/index.js");
const TUIKit_utils_env = require("../../../../utils/env.js");
const TUIKit_components_TUIChat_config = require("../../config.js");
const TUIKit_components_common_Toast_type = require("../../../common/Toast/type.js");
if (!Math) {
  Icon();
}
const Icon = () => "../../../common/Icon.js";
const _sfc_main = /* @__PURE__ */ common_vendor.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 = TUIKit_components_TUIChat_config.ChatConfig.getFeatureConfig();
    const TYPES = common_vendor.qt.TYPES;
    const actionItems = common_vendor.ref([
      {
        key: "open",
        text: common_vendor.Wt.t("TUIChat.打开"),
        iconUrl: common_assets.copyIcon,
        renderCondition() {
          var _a;
          if (!featureConfig.DownloadFile || !message.value)
            return false;
          return TUIKit_utils_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: common_vendor.Wt.t("TUIChat.复制"),
        iconUrl: common_assets.copyIcon,
        renderCondition() {
          if (!featureConfig.CopyMessage || !message.value)
            return false;
          return message.value.type === TYPES.MSG_TEXT;
        },
        clickEvent: copyMessage
      },
      {
        key: "revoke",
        text: common_vendor.Wt.t("TUIChat.撤回"),
        iconUrl: common_assets.revokeIcon,
        renderCondition() {
          if (!featureConfig.RevokeMessage || !message.value)
            return false;
          return message.value.flow === "out" && message.value.status === "success";
        },
        clickEvent: revokeMessage
      },
      {
        key: "delete",
        text: common_vendor.Wt.t("TUIChat.删除"),
        iconUrl: common_assets.delIcon,
        renderCondition() {
          if (!featureConfig.DeleteMessage || !message.value)
            return false;
          return message.value.status === "success";
        },
        clickEvent: deleteMessage
      },
      {
        key: "forward",
        text: common_vendor.Wt.t("TUIChat.转发"),
        iconUrl: common_assets.forwardIcon,
        renderCondition() {
          if (!featureConfig.ForwardMessage || !message.value)
            return false;
          return message.value.status === "success";
        },
        clickEvent: forwardSingleMessage
      },
      {
        key: "quote",
        text: common_vendor.Wt.t("TUIChat.引用"),
        iconUrl: common_assets.quoteIcon,
        renderCondition() {
          if (!featureConfig.QuoteMessage || !message.value)
            return false;
          const _message = common_vendor.Jt.getMessageModel(message.value.ID);
          return message.value.status === "success" && !_message.getSignalingInfo();
        },
        clickEvent: quoteMessage
      },
      {
        key: "translate",
        text: common_vendor.Wt.t("TUIChat.翻译"),
        visible: false,
        iconUrl: common_assets.translateIcon,
        renderCondition() {
          if (!featureConfig.TranslateMessage || !message.value)
            return false;
          return message.value.status === "success" && message.value.type === TYPES.MSG_TEXT;
        },
        clickEvent: translateMessage
      },
      {
        key: "convert",
        text: common_vendor.Wt.t("TUIChat.转文字"),
        visible: false,
        iconUrl: common_assets.convertText,
        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: common_vendor.Wt.t("TUIChat.多选"),
        iconUrl: common_assets.multipleSelectIcon,
        renderCondition() {
          if (!featureConfig.MultiSelection || !message.value)
            return false;
          return message.value.status === "success";
        },
        clickEvent: multipleSelectMessage
      }
    ]);
    const message = common_vendor.ref();
    const messageToolDom = common_vendor.ref();
    common_vendor.onMounted(() => {
      common_vendor.Jt.watch(common_vendor.o.CHAT, {
        translateTextInfo: onMessageTranslationInfoUpdated,
        voiceToTextInfo: onMessageConvertInfoUpdated
      });
    });
    common_vendor.onUnmounted(() => {
      common_vendor.Jt.unwatch(common_vendor.o.CHAT, {
        translateTextInfo: onMessageTranslationInfoUpdated,
        voiceToTextInfo: onMessageConvertInfoUpdated
      });
    });
    common_vendor.watchEffect(() => {
      message.value = common_vendor.Jt.getMessageModel(props.messageItem.ID);
    });
    const isAllActionItemInvalid = common_vendor.computed(() => {
      for (let i = 0; i < actionItems.value.length; ++i) {
        if (actionItems.value[i].renderCondition()) {
          return false;
        }
      }
      return true;
    });
    function getFunction(index) {
      actionItems.value[index].clickEvent();
    }
    function openMessage() {
      var _a;
      let url = "";
      switch ((_a = message.value) == null ? void 0 : _a.type) {
        case common_vendor.qt.TYPES.MSG_FILE:
          url = message.value.payload.fileUrl;
          break;
        case common_vendor.qt.TYPES.MSG_VIDEO:
          url = message.value.payload.remoteVideoUrl;
          break;
        case common_vendor.qt.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 = common_vendor.Jt.getMessageModel(message.value.ID);
      messageModel.revokeMessage().then(() => {
        TUIKit_utils_enableSampleTaskStatus.enableSampleTaskStatus("revokeMessage");
      }).catch((error) => {
        if (error.code === 20016 || error.code === 10031) {
          const message2 = common_vendor.Wt.t("TUIChat.已过撤回时限");
          TUIKit_components_common_Toast_index.Toast({
            message: message2,
            type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR
          });
        }
      });
    }
    function deleteMessage() {
      if (!message.value)
        return;
      const messageModel = common_vendor.Jt.getMessageModel(message.value.ID);
      messageModel.deleteMessage();
    }
    async function copyMessage() {
      var _a, _b, _c;
      if (TUIKit_utils_env.isUniFrameWork) {
        (_c = common_vendor.i) == null ? void 0 : _c.setClipboardData({
          data: TUIKit_components_TUIChat_emojiConfig_index.transformTextWithKeysToEmojiNames((_b = (_a = message.value) == null ? void 0 : _a.payload) == null ? void 0 : _b.text)
        });
      }
    }
    function beforeCopy(key) {
      if (key !== "copy" || TUIKit_utils_env.isH5) {
        return;
      }
    }
    function forwardSingleMessage() {
      if (!message.value)
        return;
      common_vendor.Jt.update(common_vendor.o.CUSTOM, "singleForwardMessageID", message.value.ID);
    }
    function quoteMessage() {
      if (!message.value)
        return;
      message.value.quoteMessage();
    }
    function translateMessage() {
      const enable = common_vendor.Jt.getData(common_vendor.o.APP, "enabledTranslationPlugin");
      if (!enable) {
        TUIKit_components_common_Toast_index.Toast({
          message: common_vendor.Wt.t("TUIChat.请开通翻译功能"),
          type: TUIKit_components_common_Toast_type.TOAST_TYPE.WARNING
        });
        return;
      }
      if (!message.value)
        return;
      const index = actionItems.value.findIndex((item) => item.key === "translate");
      common_vendor.Jt.update(common_vendor.o.CHAT, "translateTextInfo", {
        conversationID: message.value.conversationID,
        messageID: message.value.ID,
        visible: !actionItems.value[index].visible
      });
    }
    function convertVoiceToText() {
      const enable = common_vendor.Jt.getData(common_vendor.o.APP, "enabledVoiceToText");
      if (!enable) {
        TUIKit_components_common_Toast_index.Toast({
          message: common_vendor.Wt.t("TUIChat.请开通语音转文字功能")
        });
        return;
      }
      if (!message.value)
        return;
      const index = actionItems.value.findIndex((item) => item.key === "convert");
      common_vendor.Jt.update(common_vendor.o.CHAT, "voiceToTextInfo", {
        conversationID: message.value.conversationID,
        messageID: message.value.ID,
        visible: !actionItems.value[index].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 = common_vendor.Wt.t(visible ? "TUIChat.隐藏" : "TUIChat.翻译");
          actionItems.value[idx].visible = !!visible;
          return;
        }
      }
      actionItems.value[idx].text = common_vendor.Wt.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 = common_vendor.Wt.t(visible ? "TUIChat.隐藏" : "TUIChat.转文字");
          actionItems.value[idx].visible = !!visible;
          return;
        }
      }
      actionItems.value[idx].text = common_vendor.Wt.t("TUIChat.转文字");
    }
    __expose({
      messageToolDom
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !common_vendor.unref(isAllActionItemInvalid) && !_ctx.messageItem.hasRiskContent
      }, !common_vendor.unref(isAllActionItemInvalid) && !_ctx.messageItem.hasRiskContent ? common_vendor.e({
        b: common_vendor.unref(featureConfig).EmojiReaction
      }, common_vendor.unref(featureConfig).EmojiReaction ? {} : {}, {
        c: common_vendor.f(common_vendor.unref(actionItems), (item, index, i0) => {
          return common_vendor.e({
            a: item.renderCondition()
          }, item.renderCondition() ? {
            b: "a62b3471-0-" + i0,
            c: common_vendor.p({
              file: item.iconUrl,
              size: "15px"
            }),
            d: common_vendor.t(item.text),
            e: item.key,
            f: common_vendor.o$1(($event) => getFunction(index), item.key),
            g: common_vendor.o$1(($event) => beforeCopy(item.key), item.key)
          } : {});
        }),
        d: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) ? "dialog-item-list-h5" : "dialog-item-list-web"),
        e: common_vendor.n(!common_vendor.unref(TUIKit_utils_env.isPC) ? "dialog-item-h5" : "dialog-item-web")
      }) : {});
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a62b3471"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-list/message-tool/index.js.map
