"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 _hoisted_1 = { class: "room-chat" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "RoomBarrage",
  props: {
    isChatOpen: { type: Boolean, default: false }
  },
  setup(__props) {
    const props = __props;
    const barrageListRef = vue.ref(null);
    const { t } = uikitBaseComponentVue3.useUIKit();
    const { currentRoom } = room.useRoomState();
    const { localParticipant, adminList, participantList } = room.useRoomParticipantState();
    const isAdmin = (userId) => {
      var _a;
      return (_a = adminList.value) == null ? void 0 : _a.some((admin) => admin.userId === userId);
    };
    const isOwner = (userId) => {
      var _a, _b;
      return ((_b = (_a = currentRoom.value) == null ? void 0 : _a.roomOwner) == null ? void 0 : _b.userId) === userId;
    };
    const isParticipant = (userId) => {
      var _a;
      return (_a = participantList.value) == null ? void 0 : _a.some((participant) => participant.userId === userId);
    };
    const getRoleClass = (userId) => {
      if (isOwner(userId)) {
        return "user-badge-owner";
      }
      if (isAdmin(userId)) {
        return "user-badge-admin";
      }
      if (isParticipant(userId)) {
        return "user-badge-participant";
      }
      return "";
    };
    const getRoleLabel = (userId) => {
      if (isOwner(userId)) {
        return t("RoomBarrage.Host");
      }
      if (isAdmin(userId)) {
        return t("RoomBarrage.Admin");
      }
      if (isParticipant(userId)) {
        return "";
      }
      return "";
    };
    const placeholder = vue.computed(
      () => {
        var _a;
        return ((_a = localParticipant.value) == null ? void 0 : _a.isMessageDisabled) ? t("RoomChat.disabled_placeholder") : t("RoomChat.input_placeholder");
      }
    );
    vue.watch(() => props.isChatOpen, (newVal, oldVal) => {
      var _a;
      if (newVal && !oldVal && barrageListRef.value) {
        (_a = barrageListRef.value) == null ? void 0 : _a.scrollToBottom({ behavior: "smooth" });
      }
    });
    return (_ctx, _cache) => {
      var _a;
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(vue.unref(live.BarrageList), {
          ref_key: "barrageListRef",
          ref: barrageListRef,
          class: "room-message-list"
        }, {
          "user-badge": vue.withCtx(({ message }) => [
            vue.createElementVNode("span", {
              class: vue.normalizeClass(["user-badge", getRoleClass(message.sender.userId)])
            }, vue.toDisplayString(getRoleLabel(message.sender.userId)), 3)
          ]),
          _: 1
        }, 512),
        vue.createVNode(vue.unref(live.BarrageInput), {
          class: "room-message-input",
          hideSendButton: "",
          placeholder: placeholder.value,
          disabled: (_a = vue.unref(localParticipant)) == null ? void 0 : _a.isMessageDisabled
        }, null, 8, ["placeholder", "disabled"])
      ]);
    };
  }
});
exports.default = _sfc_main;
