"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const live = require("tuikit-atomicx-vue3/live");
const room = require("tuikit-atomicx-vue3/room");
const IconButton = require("../base/IconButton.vue2.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BarrageButton",
  props: {
    isChatOpen: { type: Boolean, default: false }
  },
  emits: ["click-icon"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const { t } = uikitBaseComponentVue3.useUIKit();
    const { currentRoom } = room.useRoomState();
    const { messageList } = live.useBarrageState();
    const unreadCount = vue.ref(0);
    vue.watch(
      () => {
        var _a;
        return (_a = messageList.value) == null ? void 0 : _a.length;
      },
      (newLength, oldLength) => {
        if (!newLength || newLength === 0) {
          return;
        }
        if (!props.isChatOpen && newLength > oldLength) {
          unreadCount.value += newLength - oldLength;
        }
      }
    );
    vue.watch(
      () => props.isChatOpen,
      (isOpen) => {
        if (isOpen) {
          unreadCount.value = 0;
        }
      }
    );
    vue.watch(
      () => {
        var _a;
        return (_a = currentRoom.value) == null ? void 0 : _a.roomId;
      },
      (roomId) => {
        if (!roomId) {
          return;
        }
        unreadCount.value = 0;
      }
    );
    vue.onUnmounted(() => {
    });
    const handleClick = () => {
      unreadCount.value = 0;
      emit("click-icon");
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(IconButton.default, {
        title: vue.unref(t)("Chat.Title"),
        onClickIcon: handleClick
      }, {
        default: vue.withCtx(() => [
          vue.createVNode(vue.unref(uikitBaseComponentVue3.Badge), {
            value: unreadCount.value,
            hidden: !unreadCount.value
          }, {
            default: vue.withCtx(() => [
              vue.createVNode(vue.unref(uikitBaseComponentVue3.IconChat), { size: 24 })
            ]),
            _: 1
          }, 8, ["value", "hidden"])
        ]),
        _: 1
      }, 8, ["title"]);
    };
  }
});
exports.default = _sfc_main;
