"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const RoomInvitation = require("./RoomInvitation.vue.js");
const ROOM_INVITATION_CONTAINER_ID = "room-invitation-container";
let roomInvitationContainer = null;
let currentRoomInvitationApp = null;
const hideRoomInvitation = () => {
  if (currentRoomInvitationApp) {
    vue.render(null, roomInvitationContainer);
    currentRoomInvitationApp = null;
  }
  if (roomInvitationContainer) {
    document.body.removeChild(roomInvitationContainer);
    roomInvitationContainer = null;
  }
};
const showRoomInvitation = (options) => new Promise((resolve) => {
  if (currentRoomInvitationApp) {
    hideRoomInvitation();
  }
  if (!roomInvitationContainer) {
    roomInvitationContainer = document.createElement("div");
    roomInvitationContainer.id = ROOM_INVITATION_CONTAINER_ID;
    roomInvitationContainer.style.cssText = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 10000;
      `;
    document.body.appendChild(roomInvitationContainer);
  }
  const wrappedOptions = {
    ...options,
    onAccept: () => {
      var _a;
      (_a = options.onAccept) == null ? void 0 : _a.call(options);
      hideRoomInvitation();
      resolve("accept");
    },
    onCancel: () => {
      var _a;
      (_a = options.onCancel) == null ? void 0 : _a.call(options);
      hideRoomInvitation();
      resolve("cancel");
    },
    onTimeout: () => {
      var _a;
      (_a = options.onTimeout) == null ? void 0 : _a.call(options);
      hideRoomInvitation();
      resolve("timeout");
    }
  };
  const vNode = vue.createVNode(RoomInvitation.default, {
    options: wrappedOptions
  });
  currentRoomInvitationApp = vNode;
  if (roomInvitationContainer) {
    vue.render(vNode, roomInvitationContainer);
  }
});
exports.ROOM_INVITATION_CONTAINER_ID = ROOM_INVITATION_CONTAINER_ID;
exports.hideRoomInvitation = hideRoomInvitation;
exports.showRoomInvitation = showRoomInvitation;
