"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 room = require("tuikit-atomicx-vue3/room");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "RoomInvitation",
  props: {
    options: {}
  },
  setup(__props) {
    const { t } = uikitBaseComponentVue3.useUIKit();
    const props = __props;
    const visible = vue.ref(false);
    const countdown = vue.ref(0);
    let countdownTimer = null;
    const inviterName = vue.computed(() => props.options.inviterName);
    const inviterAvatar = vue.computed(() => props.options.inviterAvatar);
    const roomName = vue.computed(() => props.options.roomName);
    const hostName = vue.computed(() => props.options.hostName);
    const participantCount = vue.computed(() => props.options.participantCount);
    const duration = vue.computed(() => props.options.duration || 30);
    const hide = () => {
      visible.value = false;
      if (countdownTimer) {
        clearInterval(countdownTimer);
        countdownTimer = null;
      }
    };
    const handleCancel = () => {
      var _a, _b;
      (_b = (_a = props.options).onCancel) == null ? void 0 : _b.call(_a);
      hide();
    };
    const handleAccept = () => {
      var _a, _b;
      (_b = (_a = props.options).onAccept) == null ? void 0 : _b.call(_a);
      hide();
    };
    const handleTimeout = () => {
      var _a, _b;
      (_b = (_a = props.options).onTimeout) == null ? void 0 : _b.call(_a);
      hide();
    };
    const startCountdown = () => {
      countdown.value = duration.value;
      countdownTimer = window.setInterval(() => {
        countdown.value -= 1;
        if (countdown.value <= 0) {
          if (countdownTimer) {
            clearInterval(countdownTimer);
            countdownTimer = null;
          }
          handleTimeout();
        }
      }, 1e3);
    };
    vue.onMounted(() => {
      visible.value = true;
      startCountdown();
    });
    vue.onBeforeUnmount(() => {
      if (countdownTimer) {
        clearInterval(countdownTimer);
      }
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.Teleport, { to: `#room-invitation-container` }, [
        vue.createVNode(vue.Transition, {
          name: "room-invitation",
          appear: ""
        }, {
          default: vue.withCtx(() => [
            visible.value ? (vue.openBlock(), vue.createElementBlock("div", {
              key: 0,
              class: vue.normalizeClass(_ctx.$style.invitationContainer)
            }, [
              vue.createElementVNode("div", {
                class: vue.normalizeClass(_ctx.$style.header)
              }, [
                vue.createVNode(vue.unref(room.Avatar), {
                  src: inviterAvatar.value,
                  size: 40,
                  class: vue.normalizeClass(_ctx.$style.avatar)
                }, null, 8, ["src", "class"]),
                vue.createElementVNode("div", {
                  class: vue.normalizeClass(_ctx.$style.inviteText)
                }, [
                  vue.createElementVNode("span", {
                    class: vue.normalizeClass(_ctx.$style.inviteTextContent)
                  }, vue.toDisplayString(vue.unref(t)("RoomInvitation.InviteText", { name: inviterName.value })), 3)
                ], 2)
              ], 2),
              vue.createElementVNode("div", {
                class: vue.normalizeClass(_ctx.$style.roomInfo)
              }, [
                vue.createElementVNode("h3", {
                  class: vue.normalizeClass(_ctx.$style.roomTitle)
                }, vue.toDisplayString(roomName.value), 3),
                vue.createElementVNode("div", {
                  class: vue.normalizeClass(_ctx.$style.roomDetails)
                }, [
                  vue.createElementVNode("span", {
                    class: vue.normalizeClass(_ctx.$style.detail)
                  }, vue.toDisplayString(vue.unref(t)("RoomInvitation.Host")) + vue.toDisplayString(hostName.value), 3),
                  vue.createElementVNode("span", {
                    class: vue.normalizeClass(_ctx.$style.divider)
                  }, "|", 2),
                  vue.createElementVNode("span", {
                    class: vue.normalizeClass(_ctx.$style.detail)
                  }, vue.toDisplayString(vue.unref(t)("RoomInvitation.Participants")) + vue.toDisplayString(participantCount.value) + vue.toDisplayString(vue.unref(t)("RoomInvitation.ParticipantsUnit")), 3)
                ], 2)
              ], 2),
              vue.createElementVNode("div", {
                class: vue.normalizeClass(_ctx.$style.dividerLine)
              }, null, 2),
              vue.createElementVNode("div", {
                class: vue.normalizeClass(_ctx.$style.actions)
              }, [
                vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
                  type: "default",
                  color: "gray",
                  size: "big",
                  onClick: handleCancel
                }, {
                  default: vue.withCtx(() => [
                    vue.createElementVNode("span", {
                      class: vue.normalizeClass(_ctx.$style.cancelText)
                    }, [
                      vue.createTextVNode(vue.toDisplayString(vue.unref(t)("RoomInvitation.NotJoin")) + " ", 1),
                      countdown.value > 0 ? (vue.openBlock(), vue.createElementBlock("span", {
                        key: 0,
                        class: vue.normalizeClass(_ctx.$style.countdown)
                      }, " (" + vue.toDisplayString(countdown.value) + "s) ", 3)) : vue.createCommentVNode("", true)
                    ], 2)
                  ]),
                  _: 1
                }),
                vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
                  type: "primary",
                  size: "big",
                  onClick: handleAccept
                }, {
                  default: vue.withCtx(() => [
                    vue.createElementVNode("span", {
                      class: vue.normalizeClass(_ctx.$style.acceptText)
                    }, [
                      vue.createVNode(vue.unref(uikitBaseComponentVue3.IconEnterRoom), { class: "icon-button" }),
                      vue.createTextVNode(" " + vue.toDisplayString(vue.unref(t)("RoomInvitation.JoinMeeting")), 1)
                    ], 2)
                  ]),
                  _: 1
                })
              ], 2)
            ], 2)) : vue.createCommentVNode("", true)
          ]),
          _: 1
        })
      ]);
    };
  }
});
exports.default = _sfc_main;
