import { defineComponent, ref, onMounted, onUnmounted, openBlock, createElementBlock, normalizeClass, unref, createVNode, createCommentVNode, createElementVNode, toDisplayString, Fragment, renderList, withModifiers } from "vue";
import "../../../adapter-vue.mjs";
import { TUIStore, StoreName, TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import { TUIConstants } from "@tencentcloud/tui-core";
import Icon from "../../common/Icon.vue.mjs";
import backIcon from "../../../assets/icon/back.svg.mjs";
import { isPC } from "../../../utils/env.mjs";
import ChatConfig from "../config.mjs";
const _hoisted_1 = { class: "chat-header-container" };
const _hoisted_2 = ["onClick"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    headerExtensionList: { default: () => [] }
  },
  emits: ["closeChat"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const currentConversation = ref();
    const currentConversationName = ref("");
    const typingStatus = ref(false);
    const groupID = ref("");
    const isNotRoomChat = ref(ChatConfig.getChatType() !== TUIConstants.TUIChat.TYPE.ROOM);
    onMounted(() => {
      TUIStore.watch(StoreName.CONV, {
        currentConversation: onCurrentConversationUpdated
      });
      TUIStore.watch(StoreName.CHAT, {
        typingStatus: onTypingStatusUpdated
      });
    });
    onUnmounted(() => {
      TUIStore.unwatch(StoreName.CONV, {
        currentConversation: onCurrentConversationUpdated
      });
      TUIStore.unwatch(StoreName.CHAT, {
        typingStatus: onTypingStatusUpdated
      });
    });
    const closeChat = (conversationID) => {
      emits("closeChat", conversationID);
    };
    const handleExtensions = (item) => {
      var _a, _b;
      (_b = (_a = item.listener).onClicked) == null ? void 0 : _b.call(_a, { groupID: groupID.value });
    };
    function onCurrentConversationUpdated(conversation) {
      var _a, _b, _c;
      currentConversation.value = conversation;
      groupID.value = (_b = (_a = currentConversation.value) == null ? void 0 : _a.groupProfile) == null ? void 0 : _b.groupID;
      currentConversationName.value = (_c = currentConversation == null ? void 0 : currentConversation.value) == null ? void 0 : _c.getShowName();
    }
    function onTypingStatusUpdated(status) {
      var _a;
      typingStatus.value = status;
      if (typingStatus.value) {
        currentConversationName.value = TUITranslateService.t("TUIChat.对方正在输入");
      } else {
        currentConversationName.value = ((_a = currentConversation.value) == null ? void 0 : _a.getShowName()) || "";
      }
    }
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(["chat-header", !unref(isPC) && "chat-header-h5"])
      }, [
        !unref(isPC) && unref(isNotRoomChat) ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: normalizeClass(["chat-header-back", !unref(isPC) && "chat-header-h5-back"]),
          onClick: _cache[0] || (_cache[0] = ($event) => closeChat(unref(currentConversation).conversationID))
        }, [
          createVNode(Icon, { file: unref(backIcon) }, null, 8, ["file"])
        ], 2)) : createCommentVNode("", true),
        createElementVNode("div", _hoisted_1, [
          unref(isNotRoomChat) ? (openBlock(), createElementBlock("div", {
            key: 0,
            class: normalizeClass(["chat-header-content", !unref(isPC) && "chat-header-h5-content"])
          }, toDisplayString(unref(currentConversationName)), 3)) : createCommentVNode("", true),
          _cache[1] || (_cache[1] = createElementVNode("div", null, null, -1))
        ]),
        createElementVNode("div", {
          class: normalizeClass(["chat-header-setting", !unref(isPC) && "chat-header-h5-setting"])
        }, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(props.headerExtensionList, (item, index) => {
            return openBlock(), createElementBlock("div", {
              key: index,
              onClick: withModifiers(($event) => handleExtensions(item), ["stop"])
            }, [
              createVNode(Icon, {
                file: item.icon
              }, null, 8, ["file"])
            ], 8, _hoisted_2);
          }), 128))
        ], 2)
      ], 2);
    };
  }
});
export {
  _sfc_main as default
};
