import { defineComponent, ref, onMounted, onUnmounted, unref, openBlock, createElementBlock, normalizeClass, createVNode, createCommentVNode } from "vue";
import "../../../../../adapter-vue.mjs";
import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
import ConvertContent from "./convert-content.vue.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    message: { default: () => ({}) }
  },
  setup(__props) {
    const props = __props;
    const convertVisible = ref(false);
    const hasConvertError = ref(false);
    const convertWrapperRef = ref();
    let isSingleConvert = true;
    onMounted(() => {
      TUIStore.watch(StoreName.CHAT, {
        voiceToTextInfo: onMessageConvertUpdated
      });
    });
    onUnmounted(() => {
      TUIStore.unwatch(StoreName.CHAT, {
        voiceToTextInfo: onMessageConvertUpdated
      });
    });
    function toggleErrorStatus(hasError) {
      hasConvertError.value = hasError;
    }
    function onMessageConvertUpdated(info) {
      if (info === void 0) return;
      isSingleConvert = false;
      const convertInfoList = info.get(props.message.conversationID) || [];
      for (let i = 0; i < convertInfoList.length; ++i) {
        const { messageID, visible } = convertInfoList[i];
        if (messageID === props.message.ID && visible !== void 0) {
          if (convertInfoList.length === 1 && visible) {
            isSingleConvert = true;
          }
          hasConvertError.value = false;
          convertVisible.value = visible;
          break;
        }
      }
    }
    return (_ctx, _cache) => {
      return unref(convertVisible) ? (openBlock(), createElementBlock("div", {
        key: 0,
        ref_key: "convertWrapperRef",
        ref: convertWrapperRef,
        class: normalizeClass({
          "message-convert": true,
          "reverse": props.message.flow === "out",
          "error": unref(hasConvertError)
        })
      }, [
        createVNode(ConvertContent, {
          message: props.message,
          contentVisible: unref(convertVisible),
          isSingleConvert: unref(isSingleConvert),
          convertWrapperRef: unref(convertWrapperRef),
          onToggleErrorStatus: toggleErrorStatus
        }, null, 8, ["message", "contentVisible", "isSingleConvert", "convertWrapperRef"])
      ], 2)) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
