import { defineComponent, ref, onMounted, onUnmounted, computed, createElementBlock, createCommentVNode, unref, openBlock, createVNode, withCtx, createElementVNode, toDisplayString } from "vue";
import { useUIKit, TUIDropdown, IconCaretDownSmall, IconCopy } from "@tencentcloud/uikit-base-component-vue3";
import { useRoomState } from "tuikit-atomicx-vue3/room";
import { useCopy } from "../../hooks/useCopy.mjs";
import { generateRoomLink } from "../../utils/utils.mjs";
const _hoisted_1 = {
  key: 0,
  class: "room-header"
};
const _hoisted_2 = { class: "room-title" };
const _hoisted_3 = { class: "room-title-name" };
const _hoisted_4 = { class: "room-duration" };
const _hoisted_5 = { class: "room-info" };
const _hoisted_6 = { class: "room-info-item" };
const _hoisted_7 = { class: "room-info-label" };
const _hoisted_8 = { class: "room-info-value" };
const _hoisted_9 = { class: "room-info-item" };
const _hoisted_10 = { class: "room-info-label" };
const _hoisted_11 = { class: "room-info-value" };
const _hoisted_12 = {
  key: 0,
  class: "room-info-item"
};
const _hoisted_13 = { class: "room-info-label" };
const _hoisted_14 = { class: "room-info-value" };
const _hoisted_15 = { class: "room-info-item" };
const _hoisted_16 = { class: "room-info-label" };
const _hoisted_17 = { class: "room-info-value" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = useUIKit();
    const { currentRoom } = useRoomState();
    const { copy } = useCopy();
    const currentTime = ref(Date.now());
    let timer = null;
    onMounted(() => {
      timer = setInterval(() => {
        currentTime.value = Date.now();
      }, 1e3);
    });
    onUnmounted(() => {
      if (timer) {
        clearInterval(timer);
      }
    });
    const roomLink = computed(() => {
      var _a;
      if (!((_a = currentRoom.value) == null ? void 0 : _a.roomId)) {
        return "";
      }
      return generateRoomLink(currentRoom.value.roomId, currentRoom.value.password, currentRoom.value.roomType);
    });
    const durationTime = computed(() => {
      var _a;
      if (!((_a = currentRoom.value) == null ? void 0 : _a.roomId)) {
        return "00:00";
      }
      const duration = currentTime.value - (currentRoom.value.createTime ?? 0);
      const totalSeconds = Math.floor(duration / 1e3);
      const hours = Math.floor(totalSeconds / 3600);
      const minutes = Math.floor(totalSeconds % 3600 / 60);
      const seconds = totalSeconds % 60;
      if (hours > 0) {
        return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
      }
      return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
    });
    return (_ctx, _cache) => {
      var _a;
      return ((_a = unref(currentRoom)) == null ? void 0 : _a.roomId) ? (openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(TUIDropdown), {
          trigger: "click",
          placement: "bottom",
          hideOnClick: false,
          teleported: false
        }, {
          dropdown: withCtx(() => {
            var _a2, _b, _c, _d, _e;
            return [
              createElementVNode("div", _hoisted_5, [
                createElementVNode("div", _hoisted_6, [
                  createElementVNode("div", _hoisted_7, toDisplayString(unref(t)("CurrentRoomInfo.Host")), 1),
                  createElementVNode("div", _hoisted_8, toDisplayString(((_a2 = unref(currentRoom)) == null ? void 0 : _a2.roomOwner.userName) || ((_b = unref(currentRoom)) == null ? void 0 : _b.roomOwner.userId)), 1)
                ]),
                createElementVNode("div", _hoisted_9, [
                  createElementVNode("div", _hoisted_10, toDisplayString(unref(t)("CurrentRoomInfo.RoomId")), 1),
                  createElementVNode("div", _hoisted_11, toDisplayString((_c = unref(currentRoom)) == null ? void 0 : _c.roomId), 1),
                  createElementVNode("div", {
                    class: "room-info-copy",
                    onClick: _cache[0] || (_cache[0] = () => {
                      var _a3;
                      return unref(copy)(((_a3 = unref(currentRoom)) == null ? void 0 : _a3.roomId) || "");
                    })
                  }, [
                    createVNode(unref(IconCopy), { class: "copy-icon" }),
                    createElementVNode("span", null, toDisplayString(unref(t)("CurrentRoomInfo.Copy")), 1)
                  ])
                ]),
                ((_d = unref(currentRoom)) == null ? void 0 : _d.password) ? (openBlock(), createElementBlock("div", _hoisted_12, [
                  createElementVNode("div", _hoisted_13, toDisplayString(unref(t)("CurrentRoomInfo.Password")), 1),
                  createElementVNode("div", _hoisted_14, toDisplayString((_e = unref(currentRoom)) == null ? void 0 : _e.password), 1),
                  createElementVNode("div", {
                    class: "room-info-copy",
                    onClick: _cache[1] || (_cache[1] = () => {
                      var _a3;
                      return unref(copy)(((_a3 = unref(currentRoom)) == null ? void 0 : _a3.password) || "");
                    })
                  }, [
                    createVNode(unref(IconCopy), { class: "copy-icon" }),
                    createElementVNode("span", null, toDisplayString(unref(t)("CurrentRoomInfo.Copy")), 1)
                  ])
                ])) : createCommentVNode("", true),
                createElementVNode("div", _hoisted_15, [
                  createElementVNode("div", _hoisted_16, toDisplayString(unref(t)("CurrentRoomInfo.RoomLink")), 1),
                  createElementVNode("div", _hoisted_17, toDisplayString(roomLink.value), 1),
                  createElementVNode("div", {
                    class: "room-info-copy",
                    onClick: _cache[2] || (_cache[2] = () => unref(copy)(roomLink.value))
                  }, [
                    createVNode(unref(IconCopy), { class: "copy-icon" }),
                    createElementVNode("span", null, toDisplayString(unref(t)("CurrentRoomInfo.Copy")), 1)
                  ])
                ])
              ])
            ];
          }),
          default: withCtx(() => {
            var _a2, _b;
            return [
              createElementVNode("div", _hoisted_2, [
                createElementVNode("span", _hoisted_3, toDisplayString(((_a2 = unref(currentRoom)) == null ? void 0 : _a2.roomName) || ((_b = unref(currentRoom)) == null ? void 0 : _b.roomId)), 1),
                createVNode(unref(IconCaretDownSmall), {
                  size: 24,
                  class: "room-title-icon"
                }),
                createElementVNode("span", _hoisted_4, toDisplayString(durationTime.value), 1)
              ])
            ];
          }),
          _: 1
        })
      ])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
