import { defineComponent, ref, onMounted, onUnmounted, openBlock, createElementBlock, createElementVNode, createVNode, toDisplayString, unref, withCtx, createCommentVNode } from "vue";
import Avatar from "../common/Avatar.vue.mjs";
import { useI18n } from "../../locales/index.mjs";
import EnterRoomIcon from "../common/icons/EnterRoomIcon.vue.mjs";
import SvgIcon from "../common/base/SvgIcon.vue.mjs";
import TuiButton from "../common/base/Button.vue.mjs";
import { TUIConferenceInvitationManagerEvents, TUIInvitationRejectedReason } from "@tencentcloud/tuiroom-engine-js";
import "../../services/main.mjs";
import { roomService } from "../../services/roomService.mjs";
import "mitt";
import "../../services/manager/roomActionManager.mjs";
import "@tencentcloud/tui-core";
import { isMobile } from "../../utils/environment.mjs";
const _hoisted_1 = {
  key: 0,
  class: "invitation-notification-container"
};
const _hoisted_2 = { class: "invitation-notification-inviter-container" };
const _hoisted_3 = { class: "invitation-notification-inviter" };
const _hoisted_4 = { class: "invitation-notification-title" };
const _hoisted_5 = { class: "invitation-notification-room-name" };
const _hoisted_6 = { class: "invitation-notification-room-info-container" };
const _hoisted_7 = { class: "invitation-notification-room-text-container" };
const _hoisted_8 = { class: "invitation-notification-room-text" };
const _hoisted_9 = { class: "invitation-notification-room-text" };
const _hoisted_10 = { class: "invitation-notification-room-text" };
const _hoisted_11 = { class: "invitation-notification-room-text" };
const _hoisted_12 = { class: "invitation-notification-bottom-container" };
const _hoisted_13 = { class: "button-text" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "InvitationNotification",
  emits: ["join-conference"],
  setup(__props, { emit: __emit }) {
    const invitationInfo = ref({
      userId: "",
      userName: "",
      avatarUrl: "",
      roomName: "",
      roomMemberCount: 0,
      roomOwner: "",
      roomId: ""
    });
    const { t } = useI18n();
    const showInvitation = ref(false);
    const emits = __emit;
    const onReceiveInvitation = (data) => {
      const { roomInfo, invitation } = data;
      invitationInfo.value.userId = invitation.inviter.userId;
      invitationInfo.value.userName = invitation.inviter.userName;
      invitationInfo.value.avatarUrl = invitation.inviter.avatarUrl;
      invitationInfo.value.roomName = roomInfo.roomName;
      invitationInfo.value.roomMemberCount = roomInfo.roomMemberCount;
      invitationInfo.value.roomOwner = roomInfo.roomOwner;
      invitationInfo.value.roomId = roomInfo.roomId;
      setInvitationDisplay(true);
    };
    const handleEnterRoom = () => {
      const { roomId } = invitationInfo.value;
      roomService.conferenceInvitationManager.accept({ roomId });
      setInvitationDisplay(false);
      emits("join-conference", {
        roomId,
        roomParam: {
          isOpenCamera: false,
          isOpenMicrophone: true
        }
      });
    };
    const handleRejectInvitation = () => {
      const { roomId } = invitationInfo.value;
      roomService.conferenceInvitationManager.reject({
        roomId,
        reason: TUIInvitationRejectedReason.kRejectToEnter
      });
      setInvitationDisplay(false);
    };
    const onInvitationTimeout = () => {
      setInvitationDisplay(false);
    };
    const setInvitationDisplay = (options) => {
      if (isMobile) {
        return;
      }
      showInvitation.value = options;
    };
    onMounted(() => {
      roomService.conferenceInvitationManager.on(
        TUIConferenceInvitationManagerEvents.onReceiveInvitation,
        onReceiveInvitation
      );
      roomService.conferenceInvitationManager.on(
        TUIConferenceInvitationManagerEvents.onInvitationTimeout,
        onInvitationTimeout
      );
    });
    onUnmounted(() => {
      roomService.conferenceInvitationManager.off(
        TUIConferenceInvitationManagerEvents.onReceiveInvitation,
        onReceiveInvitation
      );
      roomService.conferenceInvitationManager.off(
        TUIConferenceInvitationManagerEvents.onInvitationTimeout,
        onInvitationTimeout
      );
    });
    return (_ctx, _cache) => {
      return showInvitation.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          createElementVNode("div", _hoisted_3, [
            createVNode(Avatar, {
              class: "avatar",
              "img-src": invitationInfo.value.avatarUrl
            }, null, 8, ["img-src"]),
            createElementVNode("span", _hoisted_4, toDisplayString(unref(t)("sb invites you to join the conference", {
              name: invitationInfo.value.userName || invitationInfo.value.userId
            })), 1)
          ]),
          createElementVNode("span", _hoisted_5, toDisplayString(invitationInfo.value.roomName), 1),
          createElementVNode("div", _hoisted_6, [
            createElementVNode("div", _hoisted_7, [
              createElementVNode("span", _hoisted_8, toDisplayString(unref(t)("Host")) + ": ", 1),
              createElementVNode("span", _hoisted_9, toDisplayString(invitationInfo.value.roomOwner), 1)
            ]),
            _cache[0] || (_cache[0] = createElementVNode("i", { class: "invitation-notification-room-text-split" }, null, -1)),
            createElementVNode("div", null, [
              createElementVNode("span", _hoisted_10, toDisplayString(unref(t)("Attendees")) + ": ", 1),
              createElementVNode("span", _hoisted_11, toDisplayString(`${invitationInfo.value.roomMemberCount} ${unref(t)("people")}`), 1)
            ])
          ])
        ]),
        _cache[1] || (_cache[1] = createElementVNode("i", { class: "invitation-notification-bottom-split" }, null, -1)),
        createElementVNode("div", _hoisted_12, [
          createElementVNode("span", {
            class: "invitation-notification-bottom",
            onClick: handleRejectInvitation
          }, toDisplayString(unref(t)("Not joining for now")), 1),
          createVNode(TuiButton, {
            class: "button-item",
            style: { "width": "110px" },
            onClick: handleEnterRoom
          }, {
            default: withCtx(() => [
              createVNode(SvgIcon, {
                class: "icon",
                icon: EnterRoomIcon
              }),
              createElementVNode("span", _hoisted_13, toDisplayString(unref(t)("Enter Now")), 1)
            ]),
            _: 1
          })
        ])
      ])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
