import { defineComponent, computed, createElementBlock, openBlock, toDisplayString, unref, createElementVNode, createCommentVNode, createTextVNode, createVNode, withCtx } from "vue";
import { useUIKit, IconCopy, TUIButton, TUIToast } from "@tencentcloud/uikit-base-component-vue3";
import { useCopy } from "../../hooks/useCopy.mjs";
import { generateRoomLink, generateRoomSchemeLink } from "../../utils/utils.mjs";
const _hoisted_1 = { class: "room-share" };
const _hoisted_2 = {
  key: 0,
  class: "room-share-empty"
};
const _hoisted_3 = {
  key: 1,
  class: "room-share-content"
};
const _hoisted_4 = { class: "share-item" };
const _hoisted_5 = { class: "share-label" };
const _hoisted_6 = { class: "share-value" };
const _hoisted_7 = {
  key: 0,
  class: "share-item"
};
const _hoisted_8 = { class: "share-label" };
const _hoisted_9 = { class: "share-value" };
const _hoisted_10 = { class: "share-item" };
const _hoisted_11 = { class: "share-label" };
const _hoisted_12 = { class: "share-value" };
const _hoisted_13 = {
  key: 1,
  class: "share-item"
};
const _hoisted_14 = { class: "share-label" };
const _hoisted_15 = { class: "share-value" };
const _hoisted_16 = { class: "share-item" };
const _hoisted_17 = { class: "share-label" };
const _hoisted_18 = { class: "share-value room-link" };
const _hoisted_19 = { class: "room-link-text" };
const _hoisted_20 = { class: "share-item" };
const _hoisted_21 = { class: "share-label" };
const _hoisted_22 = { class: "share-value room-link" };
const _hoisted_23 = { class: "room-link-text" };
const _hoisted_24 = { class: "share-actions" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "RoomShare",
  props: {
    roomInfo: {}
  },
  setup(__props) {
    const { t } = useUIKit();
    const { copy } = useCopy();
    const props = __props;
    const formatDateTime = (timestamp) => {
      if (!timestamp) {
        return "--";
      }
      const date = new Date(timestamp * 1e3);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, "0");
      const day = date.getDate().toString().padStart(2, "0");
      const hours = date.getHours().toString().padStart(2, "0");
      const minutes = date.getMinutes().toString().padStart(2, "0");
      return `${year}-${month}-${day} ${hours}:${minutes}`;
    };
    const roomLink = computed(() => {
      var _a;
      if (!((_a = props.roomInfo) == null ? void 0 : _a.roomId)) {
        return "";
      }
      return generateRoomLink(props.roomInfo.roomId, props.roomInfo.password, props.roomInfo.roomType);
    });
    const roomSchemeLink = computed(() => {
      var _a;
      if (!((_a = props.roomInfo) == null ? void 0 : _a.roomId)) {
        return "";
      }
      return generateRoomSchemeLink(props.roomInfo.roomId, props.roomInfo.password, props.roomInfo.roomType);
    });
    const copyRoomInfoAndLink = async () => {
      if (!props.roomInfo) {
        TUIToast.error({ message: t("RoomShare.NoRoomInfo") });
        return;
      }
      const roomInfoLines = [
        `${t("RoomShare.RoomName")}: ${props.roomInfo.roomName}`,
        `${t("RoomShare.RoomId")}: ${props.roomInfo.roomId}`,
        props.roomInfo.password ? `${t("RoomShare.Password")}: ${props.roomInfo.password}` : null,
        props.roomInfo.scheduledStartTime && props.roomInfo.scheduledEndTime ? `${t("RoomShare.RoomTime")}: ${formatDateTime(props.roomInfo.scheduledStartTime)} - ${formatDateTime(props.roomInfo.scheduledEndTime)}` : null,
        `${t("RoomShare.RoomLink")}: ${roomLink.value}`,
        `${t("RoomShare.RoomSchemeLink")}: ${roomSchemeLink.value}`
      ].filter(Boolean);
      const roomInfoText = roomInfoLines.join("\n");
      await copy(roomInfoText);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        !__props.roomInfo ? (openBlock(), createElementBlock("div", _hoisted_2, toDisplayString(unref(t)("RoomShare.NoRoomInfo")), 1)) : (openBlock(), createElementBlock("div", _hoisted_3, [
          createElementVNode("div", _hoisted_4, [
            createElementVNode("div", _hoisted_5, toDisplayString(unref(t)("RoomShare.RoomName")), 1),
            createElementVNode("div", _hoisted_6, toDisplayString(__props.roomInfo.roomName), 1)
          ]),
          __props.roomInfo.scheduledStartTime && __props.roomInfo.scheduledEndTime ? (openBlock(), createElementBlock("div", _hoisted_7, [
            createElementVNode("div", _hoisted_8, toDisplayString(unref(t)("RoomShare.RoomTime")), 1),
            createElementVNode("div", _hoisted_9, toDisplayString(formatDateTime(__props.roomInfo.scheduledStartTime)) + " - " + toDisplayString(formatDateTime(__props.roomInfo.scheduledEndTime)), 1)
          ])) : createCommentVNode("", true),
          createElementVNode("div", _hoisted_10, [
            createElementVNode("div", _hoisted_11, toDisplayString(unref(t)("RoomShare.RoomId")), 1),
            createElementVNode("div", _hoisted_12, [
              createTextVNode(toDisplayString(__props.roomInfo.roomId) + " ", 1),
              createVNode(unref(IconCopy), {
                class: "copy-icon",
                onClick: _cache[0] || (_cache[0] = () => {
                  var _a;
                  return unref(copy)(((_a = __props.roomInfo) == null ? void 0 : _a.roomId) || "");
                })
              })
            ])
          ]),
          __props.roomInfo.password ? (openBlock(), createElementBlock("div", _hoisted_13, [
            createElementVNode("div", _hoisted_14, toDisplayString(unref(t)("RoomShare.Password")), 1),
            createElementVNode("div", _hoisted_15, [
              createTextVNode(toDisplayString(__props.roomInfo.password) + " ", 1),
              createVNode(unref(IconCopy), {
                class: "copy-icon",
                onClick: _cache[1] || (_cache[1] = () => {
                  var _a;
                  return unref(copy)(((_a = __props.roomInfo) == null ? void 0 : _a.password) || "");
                })
              })
            ])
          ])) : createCommentVNode("", true),
          createElementVNode("div", _hoisted_16, [
            createElementVNode("div", _hoisted_17, toDisplayString(unref(t)("RoomShare.RoomLink")), 1),
            createElementVNode("div", _hoisted_18, [
              createElementVNode("span", _hoisted_19, toDisplayString(roomLink.value), 1),
              createVNode(unref(IconCopy), {
                class: "copy-icon",
                onClick: _cache[2] || (_cache[2] = () => unref(copy)(roomLink.value))
              })
            ])
          ]),
          createElementVNode("div", _hoisted_20, [
            createElementVNode("div", _hoisted_21, toDisplayString(unref(t)("RoomShare.RoomSchemeLink")), 1),
            createElementVNode("div", _hoisted_22, [
              createElementVNode("span", _hoisted_23, toDisplayString(roomSchemeLink.value), 1),
              createVNode(unref(IconCopy), {
                class: "copy-icon",
                onClick: _cache[3] || (_cache[3] = () => unref(copy)(roomSchemeLink.value))
              })
            ])
          ]),
          createElementVNode("div", _hoisted_24, [
            createVNode(unref(TUIButton), {
              type: "primary",
              size: "large",
              class: "copy-button",
              onClick: copyRoomInfoAndLink
            }, {
              default: withCtx(() => [
                createTextVNode(toDisplayString(unref(t)("RoomShare.CopyMeetingIdAndLink")), 1)
              ]),
              _: 1
            })
          ])
        ]))
      ]);
    };
  }
});
export {
  _sfc_main as default
};
