"use strict";
const common_vendor = require("../../../../../../common/vendor.js");
require("../../../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../../../utils/env.js");
const TUIKit_components_common_Toast_index = require("../../../../common/Toast/index.js");
const TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface = require("./interface.js");
const TUIKit_components_TUIChat_emojiConfig_index = require("../../../emoji-config/index.js");
const TUIKit_components_common_Toast_type = require("../../../../common/Toast/type.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    message: { default: () => ({}) }
  },
  emits: ["scrollTo", "blinkMessage"],
  setup(__props, { emit: __emit }) {
    const emits = __emit;
    const props = __props;
    let selfAddValue = 0;
    const messageQuoteText = common_vendor.ref("");
    const hasQuoteContent = common_vendor.ref(false);
    const messageQuoteContent = common_vendor.ref({});
    const isMessageRevoked = common_vendor.computed(() => {
      var _a;
      try {
        const cloudCustomData = JSON.parse(((_a = props.message) == null ? void 0 : _a.cloudCustomData) || "{}");
        const quotedMessageModel = common_vendor.Jt.getMessageModel(cloudCustomData.messageReply.messageID);
        return quotedMessageModel == null ? void 0 : quotedMessageModel.isRevoked;
      } catch (error) {
        return true;
      }
    });
    common_vendor.onMounted(() => {
      var _a;
      try {
        const cloudCustomData = JSON.parse(((_a = props.message) == null ? void 0 : _a.cloudCustomData) || "{}");
        hasQuoteContent.value = Boolean(cloudCustomData.messageReply);
        if (hasQuoteContent.value) {
          messageQuoteContent.value = cloudCustomData.messageReply;
          messageQuoteText.value = performQuoteContent(messageQuoteContent.value);
        }
      } catch (error) {
        hasQuoteContent.value = false;
      }
    });
    function performQuoteContent(params) {
      let messageKey = "";
      let quoteContent = "";
      switch (params.messageType) {
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_TEXT:
          messageKey = "[文本]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_CUSTOM:
          messageKey = "[自定义消息]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_IMAGE:
          messageKey = "[图片]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_SOUND:
          messageKey = "[音频]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_VIDEO:
          messageKey = "[视频]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_FILE:
          messageKey = "[文件]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_LOCATION:
          messageKey = "[地理位置]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_FACE:
          messageKey = "[动画表情]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_GROUP_TIPS:
          messageKey = "[群提示]";
          break;
        case TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_MERGER:
          messageKey = "[聊天记录]";
          break;
        default:
          messageKey = "[消息]";
          break;
      }
      if ([
        TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_TEXT,
        TUIKit_components_TUIChat_messageList_messageElements_messageQuote_interface.MessageQuoteTypeEnum.TYPE_MERGER
      ].includes(params.messageType)) {
        quoteContent = params.messageAbstract;
      }
      return quoteContent ? quoteContent : common_vendor.Wt.t(`TUIChat.${messageKey}`);
    }
    async function scrollToOriginalMessage() {
      var _a;
      if (isMessageRevoked.value) {
        return;
      }
      const originMessageID = (_a = messageQuoteContent.value) == null ? void 0 : _a.messageID;
      const currentMessageList = common_vendor.Jt.getData(common_vendor.o.CHAT, "messageList");
      const isOriginalMessageInScreen = currentMessageList.some((msg) => msg.ID === originMessageID);
      if (originMessageID && isOriginalMessageInScreen) {
        try {
          const scrollViewRect = await common_vendor.T("#messageScrollList", "messageList");
          const originalMessageRect = await common_vendor.T("#tui-" + originMessageID, "messageList");
          const { scrollTop } = await common_vendor.P("#messageScrollList", "messageList");
          const finalScrollTop = originalMessageRect.top + scrollTop - scrollViewRect.top - selfAddValue++ % 2;
          const isNeedScroll = originalMessageRect.top < scrollViewRect.top;
          if (!TUIKit_utils_env.isUniFrameWork && window) {
            const scrollView = document.getElementById("messageScrollList");
            if (isNeedScroll && scrollView) {
              scrollView.scrollTop = finalScrollTop;
            }
          } else if (TUIKit_utils_env.isUniFrameWork && isNeedScroll) {
            emits("scrollTo", finalScrollTop);
          }
          emits("blinkMessage", originMessageID);
        } catch (error) {
          common_vendor.index.__f__("error", "at TUIKit/components/TUIChat/message-list/message-elements/message-quote/index.vue:154", error);
        }
      } else {
        TUIKit_components_common_Toast_index.Toast({
          message: common_vendor.Wt.t("TUIChat.无法定位到原消息"),
          type: TUIKit_components_common_Toast_type.TOAST_TYPE.WARNING
        });
      }
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(hasQuoteContent)
      }, common_vendor.unref(hasQuoteContent) ? common_vendor.e({
        b: common_vendor.unref(isMessageRevoked)
      }, common_vendor.unref(isMessageRevoked) ? {
        c: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIChat.引用内容已撤回"))
      } : {
        d: common_vendor.t(common_vendor.unref(messageQuoteContent).messageSender),
        e: common_vendor.t(common_vendor.unref(TUIKit_components_TUIChat_emojiConfig_index.transformTextWithKeysToEmojiNames)(common_vendor.unref(messageQuoteText)))
      }, {
        f: _ctx.message.flow === "out" ? 1 : "",
        g: common_vendor.o$1(scrollToOriginalMessage)
      }) : {});
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3506872c"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/message-list/message-elements/message-quote/index.js.map
