import { defineComponent, ref, computed, onMounted, onBeforeUnmount, createBlock, openBlock, Teleport, createVNode, Transition, withCtx, createElementBlock, createCommentVNode, normalizeClass, createElementVNode, unref, toDisplayString, createTextVNode } from "vue";
import { useUIKit, TUIButton, IconEnterRoom } from "@tencentcloud/uikit-base-component-vue3";
import { Avatar } from "tuikit-atomicx-vue3/room";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "RoomInvitation",
  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-container` }, [
        createVNode(Transition, {
          name: "room-invitation",
          appear: ""
        }, {
          default: withCtx(() => [
            visible.value ? (openBlock(), createElementBlock("div", {
              key: 0,
              class: normalizeClass(_ctx.$style.invitationContainer)
            }, [
              createElementVNode("div", {
                class: normalizeClass(_ctx.$style.header)
              }, [
                createVNode(unref(Avatar), {
                  src: inviterAvatar.value,
                  size: 40,
                  class: normalizeClass(_ctx.$style.avatar)
                }, null, 8, ["src", "class"]),
                createElementVNode("div", {
                  class: normalizeClass(_ctx.$style.inviteText)
                }, [
                  createElementVNode("span", {
                    class: normalizeClass(_ctx.$style.inviteTextContent)
                  }, toDisplayString(unref(t)("RoomInvitation.InviteText", { name: inviterName.value })), 3)
                ], 2)
              ], 2),
              createElementVNode("div", {
                class: normalizeClass(_ctx.$style.roomInfo)
              }, [
                createElementVNode("h3", {
                  class: normalizeClass(_ctx.$style.roomTitle)
                }, toDisplayString(roomName.value), 3),
                createElementVNode("div", {
                  class: normalizeClass(_ctx.$style.roomDetails)
                }, [
                  createElementVNode("span", {
                    class: normalizeClass(_ctx.$style.detail)
                  }, toDisplayString(unref(t)("RoomInvitation.Host")) + toDisplayString(hostName.value), 3),
                  createElementVNode("span", {
                    class: normalizeClass(_ctx.$style.divider)
                  }, "|", 2),
                  createElementVNode("span", {
                    class: normalizeClass(_ctx.$style.detail)
                  }, toDisplayString(unref(t)("RoomInvitation.Participants")) + toDisplayString(participantCount.value) + toDisplayString(unref(t)("RoomInvitation.ParticipantsUnit")), 3)
                ], 2)
              ], 2),
              createElementVNode("div", {
                class: normalizeClass(_ctx.$style.dividerLine)
              }, null, 2),
              createElementVNode("div", {
                class: normalizeClass(_ctx.$style.actions)
              }, [
                createVNode(unref(TUIButton), {
                  type: "default",
                  color: "gray",
                  size: "big",
                  onClick: handleCancel
                }, {
                  default: withCtx(() => [
                    createElementVNode("span", {
                      class: normalizeClass(_ctx.$style.cancelText)
                    }, [
                      createTextVNode(toDisplayString(unref(t)("RoomInvitation.NotJoin")) + " ", 1),
                      countdown.value > 0 ? (openBlock(), createElementBlock("span", {
                        key: 0,
                        class: normalizeClass(_ctx.$style.countdown)
                      }, " (" + toDisplayString(countdown.value) + "s) ", 3)) : createCommentVNode("", true)
                    ], 2)
                  ]),
                  _: 1
                }),
                createVNode(unref(TUIButton), {
                  type: "primary",
                  size: "big",
                  onClick: handleAccept
                }, {
                  default: withCtx(() => [
                    createElementVNode("span", {
                      class: normalizeClass(_ctx.$style.acceptText)
                    }, [
                      createVNode(unref(IconEnterRoom), { class: "icon-button" }),
                      createTextVNode(" " + toDisplayString(unref(t)("RoomInvitation.JoinMeeting")), 1)
                    ], 2)
                  ]),
                  _: 1
                })
              ], 2)
            ], 2)) : createCommentVNode("", true)
          ]),
          _: 1
        })
      ]);
    };
  }
});
export {
  _sfc_main as default
};
