import { defineComponent, toRefs, computed, openBlock, createElementBlock, normalizeClass, unref, createBlock, createCommentVNode, createElementVNode, createVNode, withModifiers, toDisplayString, Fragment, renderSlot } from "vue";
import "../../../../adapter-vue.mjs";
import TUIChatEngine, { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import Icon from "../../../common/Icon.vue.mjs";
import ReadStatus from "./read-status/index.vue.mjs";
import MessageQuote from "./message-quote/index.vue.mjs";
import Avatar from "../../../common/Avatar/index.vue.mjs";
import MessageTranslate from "./message-translate/index.vue.mjs";
import MessageConvert from "./message-convert/index.vue.mjs";
import RadioSelect from "../../../common/RadioSelect/index.vue.mjs";
import loadingIcon from "../../../../assets/icon/loading.png.mjs";
import { shallowCopyMessage } from "../../utils/utils.mjs";
import { isPC } from "../../../../utils/env.mjs";
const _hoisted_1 = { class: "message-bubble-content" };
const _hoisted_2 = {
  key: 0,
  class: "message-body-nick-name"
};
const _hoisted_3 = { class: "content-main" };
const _hoisted_4 = {
  key: 0,
  class: "content-has-risk-tips"
};
const _hoisted_5 = {
  key: 0,
  class: "audio-unplay-mark"
};
const _hoisted_6 = { class: "message-bubble-extra-content" };
const riskImageReplaceUrl = "https://web.sdk.qcloud.com/component/TUIKit/assets/has_risk_default.png";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "message-bubble",
  props: {
    messageItem: { default: () => ({}) },
    content: { default: () => ({}) },
    classNameList: { default: () => [] },
    blinkMessageIDList: { default: () => [] },
    isMultipleSelectMode: { type: Boolean, default: false },
    isAudioPlayed: { type: Boolean, default: false },
    multipleSelectedMessageIDList: { default: () => [] }
  },
  emits: ["resendMessage", "blinkMessage", "setReadReceiptPanelVisible", "changeSelectMessageIDList", "scrollTo"],
  setup(__props, { emit: __emit }) {
    const emits = __emit;
    const props = __props;
    const TYPES = TUIChatEngine.TYPES;
    const needLoadingIconMessageType = [
      TYPES.MSG_LOCATION,
      TYPES.MSG_TEXT,
      TYPES.MSG_CUSTOM,
      TYPES.MSG_MERGER,
      TYPES.MSG_FACE
    ];
    const { blinkMessageIDList, messageItem: message } = toRefs(props);
    const isMultipleSelected = computed(() => {
      return props.multipleSelectedMessageIDList.includes(message.value.ID);
    });
    const isDisplayUnplayMark = computed(() => {
      return message.value.flow === "in" && message.value.status === "success" && message.value.type === TYPES.MSG_AUDIO && !props.isAudioPlayed;
    });
    const containerClassNameList = computed(() => {
      return [
        "message-bubble",
        isMultipleSelected.value ? "multiple-selected" : "",
        ...props.classNameList
      ];
    });
    const hasEmojiReaction = computed(() => {
      var _a;
      return (_a = message.value) == null ? void 0 : _a.reactionList.some((item) => item.totalUserCount !== 0);
    });
    const isNoPadding = computed(() => {
      return !hasEmojiReaction.value && [TYPES.MSG_IMAGE, TYPES.MSG_VIDEO, TYPES.MSG_MERGER].includes(message.value.type);
    });
    const riskContentText = computed(() => {
      let content = TUITranslateService.t("TUIChat.涉及敏感内容") + ", ";
      if (message.value.flow === "out") {
        content += TUITranslateService.t("TUIChat.发送失败");
      } else {
        content += TUITranslateService.t(
          message.value.type === TYPES.MSG_AUDIO ? "TUIChat.无法收听" : "TUIChat.无法查看"
        );
      }
      return content;
    });
    const isBlink = computed(() => {
      var _a, _b;
      if ((_a = message.value) == null ? void 0 : _a.ID) {
        return (_b = blinkMessageIDList == null ? void 0 : blinkMessageIDList.value) == null ? void 0 : _b.includes(message.value.ID);
      }
      return false;
    });
    function toggleMultipleSelect(isSelected) {
      emits("changeSelectMessageIDList", {
        type: isSelected ? "add" : "remove",
        messageID: message.value.ID
      });
    }
    function resendMessage() {
      var _a;
      if (!((_a = message.value) == null ? void 0 : _a.hasRiskContent)) {
        emits("resendMessage");
      }
    }
    function blinkMessage(messageID) {
      emits("blinkMessage", messageID);
    }
    function scrollTo(scrollHeight) {
      emits("scrollTo", scrollHeight);
    }
    function openReadUserPanel() {
      emits("setReadReceiptPanelVisible", true, message.value);
    }
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(unref(containerClassNameList))
      }, [
        props.isMultipleSelectMode ? (openBlock(), createBlock(RadioSelect, {
          key: 0,
          class: "multiple-select-radio",
          isSelected: unref(isMultipleSelected),
          onOnChange: toggleMultipleSelect
        }, null, 8, ["isSelected"])) : createCommentVNode("", true),
        createElementVNode("div", {
          class: normalizeClass({
            "control-reverse": unref(message).flow === "out"
          })
        }, [
          createElementVNode("div", _hoisted_1, [
            createElementVNode("div", {
              class: normalizeClass(["message-bubble-main-content", [unref(message).flow === "in" ? "" : "reverse"]])
            }, [
              createVNode(Avatar, {
                useSkeletonAnimation: "",
                url: unref(message).avatar || ""
              }, null, 8, ["url"]),
              createElementVNode("main", {
                class: "message-body",
                onClick: _cache[1] || (_cache[1] = withModifiers(() => {
                }, ["stop"]))
              }, [
                unref(message).flow === "in" && unref(message).conversationType === "GROUP" ? (openBlock(), createElementBlock("div", _hoisted_2, toDisplayString(props.content.showName), 1)) : createCommentVNode("", true),
                createElementVNode("div", {
                  class: normalizeClass(["message-body-main", unref(message).flow === "out" && "message-body-main-reverse"])
                }, [
                  createElementVNode("div", {
                    class: normalizeClass([
                      "blink",
                      "message-body-content",
                      unref(message).flow === "out" ? "content-out" : "content-in",
                      unref(message).hasRiskContent && "content-has-risk",
                      unref(isNoPadding) ? "content-no-padding" : "",
                      unref(isNoPadding) && unref(isBlink) ? "blink-shadow" : "",
                      !unref(isNoPadding) && unref(isBlink) ? "blink-content" : ""
                    ])
                  }, [
                    createElementVNode("div", _hoisted_3, [
                      (unref(message).type === unref(TYPES).MSG_IMAGE || unref(message).type === unref(TYPES).MSG_VIDEO) && unref(message).hasRiskContent ? (openBlock(), createElementBlock("img", {
                        key: 0,
                        class: normalizeClass(["message-risk-replace", !unref(isPC) && "message-risk-replace-h5"]),
                        src: riskImageReplaceUrl
                      }, null, 2)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                        renderSlot(_ctx.$slots, "messageElement", {}, void 0, true),
                        renderSlot(_ctx.$slots, "TUIEmojiPlugin", {}, void 0, true)
                      ], 64))
                    ]),
                    unref(message).hasRiskContent ? (openBlock(), createElementBlock("div", _hoisted_4, toDisplayString(unref(riskContentText)), 1)) : createCommentVNode("", true)
                  ], 2),
                  unref(isDisplayUnplayMark) ? (openBlock(), createElementBlock("div", _hoisted_5)) : createCommentVNode("", true),
                  unref(message).status === "fail" || unref(message).hasRiskContent ? (openBlock(), createElementBlock("div", {
                    key: 1,
                    class: "message-label fail",
                    onClick: _cache[0] || (_cache[0] = ($event) => resendMessage())
                  }, " ! ")) : createCommentVNode("", true),
                  unref(message).status === "unSend" && needLoadingIconMessageType.includes(unref(message).type) ? (openBlock(), createBlock(Icon, {
                    key: 2,
                    class: "message-label loading-circle",
                    file: unref(loadingIcon),
                    width: "15px",
                    height: "15px"
                  }, null, 8, ["file"])) : createCommentVNode("", true),
                  createVNode(ReadStatus, {
                    class: "message-label align-self-bottom",
                    message: unref(shallowCopyMessage)(unref(message)),
                    onOpenReadUserPanel: openReadUserPanel
                  }, null, 8, ["message"])
                ], 2)
              ])
            ], 2),
            createElementVNode("div", _hoisted_6, [
              createVNode(MessageTranslate, {
                class: normalizeClass(unref(message).flow === "out" ? "reverse" : "flex-row"),
                message: unref(message)
              }, null, 8, ["class", "message"]),
              createVNode(MessageConvert, {
                class: normalizeClass(unref(message).flow === "out" ? "reverse" : "flex-row"),
                message: unref(message)
              }, null, 8, ["class", "message"]),
              createVNode(MessageQuote, {
                class: normalizeClass(unref(message).flow === "out" ? "reverse" : "flex-row"),
                message: unref(message),
                onBlinkMessage: blinkMessage,
                onScrollTo: scrollTo
              }, null, 8, ["class", "message"])
            ])
          ])
        ], 2)
      ], 2);
    };
  }
});
export {
  _sfc_main as default
};
