import { defineComponent, ref, computed, onMounted, onBeforeUnmount, createBlock, openBlock, Teleport, createVNode, Transition, withCtx, createElementBlock, createCommentVNode, createElementVNode, normalizeStyle, unref, toDisplayString } from "vue";
import { useUIKit, IconClose, IconArrowStrokeUp } from "@tencentcloud/uikit-base-component-vue3";
import { Avatar } from "tuikit-atomicx-vue3/room";
const _hoisted_1 = {
  key: 0,
  class: "invitation-container"
};
const _hoisted_2 = { class: "content" };
const _hoisted_3 = { class: "room-info-container" };
const _hoisted_4 = { class: "avatar-wrapper" };
const _hoisted_5 = { class: "invite-text" };
const _hoisted_6 = { class: "room-info" };
const _hoisted_7 = { class: "room-title" };
const _hoisted_8 = { class: "room-details" };
const _hoisted_9 = { class: "detail" };
const _hoisted_10 = { class: "detail" };
const _hoisted_11 = { class: "actions" };
const _hoisted_12 = { class: "reject-button" };
const _hoisted_13 = { class: "reject-button-text" };
const _hoisted_14 = { class: "accept-button" };
const _hoisted_15 = { class: "accept-button-text" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "RoomInvitationH5",
  props: {
    options: {}
  },
  setup(__props) {
    const { t } = useUIKit();
    const props = __props;
    const visible = ref(false);
    const countdown = ref(0);
    let countdownTimer = null;
    const inviterName = computed(() => props.options.inviterName);
    const inviterAvatar = computed(() => props.options.inviterAvatar);
    const roomName = computed(() => props.options.roomName);
    const hostName = computed(() => props.options.hostName);
    const participantCount = computed(() => props.options.participantCount);
    const duration = 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);
    };
    onMounted(() => {
      visible.value = true;
      startCountdown();
    });
    onBeforeUnmount(() => {
      if (countdownTimer) {
        clearInterval(countdownTimer);
      }
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(Teleport, { to: `#room-invitation-h5-container` }, [
        createVNode(Transition, {
          name: "room-invitation-h5",
          appear: ""
        }, {
          default: withCtx(() => [
            visible.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
              createElementVNode("div", {
                class: "background-blur",
                style: normalizeStyle({ backgroundImage: `url(${inviterAvatar.value})` })
              }, null, 4),
              _cache[1] || (_cache[1] = createElementVNode("div", { class: "background-mask" }, null, -1)),
              createElementVNode("div", _hoisted_2, [
                createElementVNode("div", _hoisted_3, [
                  createElementVNode("div", _hoisted_4, [
                    createVNode(unref(Avatar), {
                      src: inviterAvatar.value,
                      size: 60,
                      class: "avatar"
                    }, null, 8, ["src"])
                  ]),
                  createElementVNode("div", _hoisted_5, toDisplayString(unref(t)("RoomInvitation.InviteText", { name: inviterName.value })), 1),
                  createElementVNode("div", _hoisted_6, [
                    createElementVNode("div", _hoisted_7, toDisplayString(roomName.value), 1),
                    createElementVNode("div", _hoisted_8, [
                      createElementVNode("span", _hoisted_9, toDisplayString(unref(t)("RoomInvitation.Host")) + toDisplayString(hostName.value), 1),
                      _cache[0] || (_cache[0] = createElementVNode("span", { class: "divider" }, "|", -1)),
                      createElementVNode("span", _hoisted_10, toDisplayString(unref(t)("RoomInvitation.Participants")) + toDisplayString(participantCount.value) + toDisplayString(unref(t)("RoomInvitation.ParticipantsUnit")), 1)
                    ])
                  ])
                ]),
                createElementVNode("div", _hoisted_11, [
                  createElementVNode("div", {
                    class: "action-item",
                    onClick: handleCancel
                  }, [
                    createElementVNode("span", _hoisted_12, [
                      createVNode(unref(IconClose), {
                        size: "18",
                        class: "reject-button-icon"
                      })
                    ]),
                    createElementVNode("span", _hoisted_13, toDisplayString(unref(t)("RoomInvitation.NotJoin")), 1)
                  ]),
                  createElementVNode("div", {
                    class: "action-item",
                    onClick: handleAccept
                  }, [
                    createElementVNode("span", _hoisted_14, [
                      createVNode(unref(IconArrowStrokeUp), {
                        size: "18",
                        class: "accept-button-icon"
                      })
                    ]),
                    createElementVNode("span", _hoisted_15, toDisplayString(unref(t)("RoomInvitation.JoinMeeting")), 1)
                  ])
                ])
              ])
            ])) : createCommentVNode("", true)
          ]),
          _: 1
        })
      ]);
    };
  }
});
export {
  _sfc_main as default
};
