import { defineComponent, ref, onMounted, onUnmounted, unref, openBlock, createElementBlock, normalizeClass, createVNode, createElementVNode, toDisplayString, createCommentVNode } from "vue";
import "../../../../../adapter-vue.mjs";
import { TUIStore, StoreName, TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import Icon from "../../../../common/Icon.vue.mjs";
import TranslationContent from "./translation-content.vue.mjs";
import checkIcon from "../../../../../assets/icon/check-sm.svg.mjs";
const _hoisted_1 = { class: "copyright" };
const _hoisted_2 = { class: "copyright-text" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    message: { default: () => ({}) }
  },
  setup(__props) {
    const props = __props;
    const translationVisible = ref(false);
    const hasTranslationError = ref(false);
    const translationWrapperRef = ref();
    let isSingleTranslation = true;
    onMounted(() => {
      TUIStore.watch(StoreName.CHAT, {
        translateTextInfo: onMessageTranslationUpdated
      });
    });
    onUnmounted(() => {
      TUIStore.unwatch(StoreName.CHAT, {
        translateTextInfo: onMessageTranslationUpdated
      });
    });
    function toggleErrorStatus(hasError) {
      hasTranslationError.value = hasError;
    }
    function onMessageTranslationUpdated(info) {
      if (info === void 0) return;
      isSingleTranslation = false;
      const translationInfoList = info.get(props.message.conversationID) || [];
      for (let i = 0; i < translationInfoList.length; ++i) {
        const { messageID, visible } = translationInfoList[i];
        if (messageID === props.message.ID && visible !== void 0) {
          if (translationInfoList.length === 1 && visible) {
            isSingleTranslation = true;
          }
          hasTranslationError.value = false;
          translationVisible.value = visible;
          break;
        }
      }
    }
    return (_ctx, _cache) => {
      return unref(translationVisible) ? (openBlock(), createElementBlock("div", {
        key: 0,
        ref_key: "translationWrapperRef",
        ref: translationWrapperRef,
        class: normalizeClass({
          "message-translation": true,
          "reverse": props.message.flow === "out",
          "error": unref(hasTranslationError)
        })
      }, [
        createVNode(TranslationContent, {
          message: props.message,
          translationContentVisible: unref(translationVisible),
          translationWrapperRef: unref(translationWrapperRef),
          isSingleTranslation: unref(isSingleTranslation),
          onToggleErrorStatus: toggleErrorStatus
        }, null, 8, ["message", "translationContentVisible", "translationWrapperRef", "isSingleTranslation"]),
        createElementVNode("div", _hoisted_1, [
          createVNode(Icon, {
            file: unref(checkIcon),
            size: "13px"
          }, null, 8, ["file"]),
          createElementVNode("div", _hoisted_2, toDisplayString(unref(TUITranslateService).t("TUIChat.由IM提供翻译支持")), 1)
        ])
      ], 2)) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
