import { createVNode, render } from "vue";
import RoomInvitationH5 from "./RoomInvitationH5.vue2.mjs";
const ROOM_INVITATION_H5_CONTAINER_ID = "room-invitation-h5-container";
let roomInvitationH5Container = null;
let currentRoomInvitationH5App = null;
const hideRoomInvitationH5 = () => {
  if (currentRoomInvitationH5App) {
    render(null, roomInvitationH5Container);
    currentRoomInvitationH5App = null;
  }
  if (roomInvitationH5Container) {
    document.body.removeChild(roomInvitationH5Container);
    roomInvitationH5Container = null;
  }
};
const showRoomInvitationH5 = (options) => new Promise((resolve) => {
  if (currentRoomInvitationH5App) {
    hideRoomInvitationH5();
  }
  if (!roomInvitationH5Container) {
    roomInvitationH5Container = document.createElement("div");
    roomInvitationH5Container.id = ROOM_INVITATION_H5_CONTAINER_ID;
    roomInvitationH5Container.style.cssText = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10000;
      `;
    document.body.appendChild(roomInvitationH5Container);
  }
  const wrappedOptions = {
    ...options,
    onAccept: () => {
      var _a;
      (_a = options.onAccept) == null ? void 0 : _a.call(options);
      hideRoomInvitationH5();
      resolve("accept");
    },
    onCancel: () => {
      var _a;
      (_a = options.onCancel) == null ? void 0 : _a.call(options);
      hideRoomInvitationH5();
      resolve("cancel");
    },
    onTimeout: () => {
      var _a;
      (_a = options.onTimeout) == null ? void 0 : _a.call(options);
      hideRoomInvitationH5();
      resolve("timeout");
    }
  };
  const vNode = createVNode(RoomInvitationH5, {
    options: wrappedOptions
  });
  currentRoomInvitationH5App = vNode;
  if (roomInvitationH5Container) {
    render(vNode, roomInvitationH5Container);
  }
});
export {
  ROOM_INVITATION_H5_CONTAINER_ID,
  hideRoomInvitationH5,
  showRoomInvitationH5
};
