import { defineComponent, ref, onMounted, onUnmounted, computed, createElementBlock, openBlock, Fragment, createCommentVNode, createVNode, unref, createElementVNode, toDisplayString, withCtx } from "vue";
import { IconCaretDownSmall, TUIPopup } from "@tencentcloud/uikit-base-component-vue3";
import { useRoomState } from "tuikit-atomicx-vue3/room";
import PopUpArrowDown from "../base/PopUpArrowDown.vue2.mjs";
import CurrentRoomInfoH5 from "./CurrentRoomInfo.vue2.mjs";
const _hoisted_1 = { class: "room-title" };
const _hoisted_2 = { class: "room-title-top" };
const _hoisted_3 = { class: "room-title-name" };
const _hoisted_4 = { class: "room-duration" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { currentRoom } = useRoomState();
    const isPopupVisible = ref(false);
    const currentTime = ref(Date.now());
    let timer = null;
    onMounted(() => {
      timer = setInterval(() => {
        currentTime.value = Date.now();
      }, 1e3);
    });
    onUnmounted(() => {
      if (timer) {
        clearInterval(timer);
      }
    });
    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, _b, _c;
      return openBlock(), createElementBlock(Fragment, null, [
        ((_a = unref(currentRoom)) == null ? void 0 : _a.roomId) ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: "room-header",
          onClick: _cache[0] || (_cache[0] = ($event) => isPopupVisible.value = true)
        }, [
          createElementVNode("div", _hoisted_1, [
            createElementVNode("div", _hoisted_2, [
              createElementVNode("span", _hoisted_3, toDisplayString(((_b = unref(currentRoom)) == null ? void 0 : _b.roomName) || ((_c = unref(currentRoom)) == null ? void 0 : _c.roomId)), 1),
              createVNode(unref(IconCaretDownSmall), {
                size: 24,
                class: "room-title-icon"
              })
            ]),
            createElementVNode("span", _hoisted_4, toDisplayString(durationTime.value), 1)
          ])
        ])) : createCommentVNode("", true),
        createVNode(unref(TUIPopup), {
          visible: isPopupVisible.value,
          "onUpdate:visible": _cache[2] || (_cache[2] = ($event) => isPopupVisible.value = $event)
        }, {
          default: withCtx(() => [
            createVNode(PopUpArrowDown, {
              onClick: _cache[1] || (_cache[1] = ($event) => isPopupVisible.value = false)
            }),
            createVNode(CurrentRoomInfoH5)
          ]),
          _: 1
        }, 8, ["visible"])
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
