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