"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const basic = require("../../stores/basic.js");
const room = require("../../stores/room.js");
const Message = require("../common/base/Message/Message.js");
const pinia = require("pinia");
const index = require("../../locales/index.js");
const utils = require("../../utils/utils.js");
const environment = require("../../utils/environment.js");
const InviteIcon = require("../common/icons/InviteIcon.vue.js");
const ShareIcon = require("../common/icons/ShareIcon.vue.js");
require("../../services/main.js");
const roomService = require("../../services/roomService.js");
require("@tencentcloud/tuiroom-engine-js");
require("mitt");
require("../../services/manager/roomActionManager.js");
require("@tencentcloud/tui-core");
const message = require("../../constants/message.js");
const adapter = require("../../utils/adapter.js");
function useRoomInvite() {
  const { t } = index.useI18n();
  const basicStore = basic.useBasicStore();
  const roomLinkConfig = roomService.roomService.getComponentConfig("RoomLink");
  const roomStore = room.useRoomStore();
  const { remoteEnteredUserList, roomName, isSeatEnabled, password } = pinia.storeToRefs(roomStore);
  const {
    roomId,
    shareLink,
    isRoomLinkVisible,
    isSchemeLinkVisible,
    userId,
    userName
  } = pinia.storeToRefs(basicStore);
  const { origin, pathname } = location || {};
  const isShowLink = Vue.ref(true);
  const showContacts = Vue.ref(false);
  const showRoomInvite = Vue.ref(false);
  const inviteLink = Vue.computed(() => {
    if (shareLink.value) {
      const urlConcatenation = shareLink.value.indexOf("?") !== -1 ? "&" : "?";
      return `${shareLink.value}${urlConcatenation}roomId=${roomId.value}`;
    }
    return `${origin}${pathname}#/home?roomId=${roomId.value}`;
  });
  const schemeLink = Vue.computed(
    () => `tuiroom://joinroom?roomId=${roomId.value}`
  );
  const inviteBarTitle = Vue.computed(
    () => isRoomLinkVisible.value ? t(
      "You can share the room number or link to invite more people to join the room."
    ) : t(
      "You can share the room number to invite more people to join the room"
    )
  );
  const isShowPassword = Vue.computed(() => !!(password == null ? void 0 : password.value));
  const invitationFeatureDetails = Vue.ref([
    {
      icon: InviteIcon.default,
      text: "addMember",
      function: async () => {
        contacts.value = await roomService.roomService.scheduleConferenceManager.fetchFriendList();
        showContacts.value = true;
      }
    },
    {
      icon: ShareIcon.default,
      text: "shareRoom",
      function: () => {
        showRoomInvite.value = true;
      }
    }
  ]);
  const contacts = Vue.ref([]);
  async function onCopy(value) {
    try {
      await adapter.clipBoard(value);
      Message.default({
        message: t("Copied successfully"),
        type: "success"
      });
    } catch (error) {
      Message.default({
        message: t("Copied failure"),
        type: "error"
      });
    }
  }
  const inviteContentList = Vue.computed(() => [
    {
      id: 1,
      mobileTitle: "Room ID",
      pcTitle: "Invite by room number",
      content: roomId.value,
      copyLink: roomId.value,
      visible: isShowLink.value
    },
    {
      id: 2,
      mobileTitle: "Room Link",
      pcTitle: "Invite via room link",
      content: inviteLink.value,
      copyLink: inviteLink.value,
      visible: isRoomLinkVisible.value
    },
    {
      id: 3,
      mobileTitle: "scheme",
      pcTitle: "Invite via client scheme",
      content: schemeLink.value,
      copyLink: schemeLink.value,
      visible: isSchemeLinkVisible.value
    }
  ]);
  const visibleInviteContentList = Vue.computed(
    () => inviteContentList.value.filter((item) => item.visible)
  );
  const conferenceInviteList = Vue.computed(() => [
    {
      title: "Room Name",
      content: roomName.value,
      isShowCopyIcon: false,
      isVisible: true
    },
    {
      title: "Room Type",
      content: `${t(getSeatModeDisplay(isSeatEnabled.value))}`,
      isShowCopyIcon: false,
      isVisible: true
    },
    {
      title: "Room ID",
      content: roomId.value,
      isShowCopyIcon: true,
      isVisible: true
    },
    {
      title: "Room Password",
      content: password == null ? void 0 : password.value,
      isShowCopyIcon: true,
      isVisible: isShowPassword.value
    },
    {
      title: "Room Link",
      content: utils.getUrlWithRoomId(roomId.value),
      isShowCopyIcon: true,
      isVisible: isRoomLinkVisible.value && roomLinkConfig.visible
    }
  ]);
  function getSeatModeDisplay(isSeatEnabled2) {
    return isSeatEnabled2 ? "On-stage Speaking Room" : "Free Speech Room";
  }
  function copyRoomIdAndRoomLink() {
    const invitationList = [
      roomName.value,
      `${t("Room Type")}: ${t(getSeatModeDisplay(isSeatEnabled.value))}`,
      `${t("Room ID")}: ${roomId.value}`
    ];
    if (isShowPassword.value) {
      invitationList.push(`${t("Room Password")}: ${password == null ? void 0 : password.value}`);
    }
    if (isRoomLinkVisible.value && roomLinkConfig.visible) {
      invitationList.push(
        `${t("Room Link")}: ${utils.getUrlWithRoomId(roomId.value)}`
      );
    }
    const invitation = invitationList.join("\n");
    onCopy(invitation);
    showRoomInvite.value = false;
  }
  const contactsConfirm = async (contacts2) => {
    const userIdList = contacts2.map((contacts3) => contacts3.userId);
    await roomService.roomService.conferenceInvitationManager.inviteUsers({ userIdList });
    Message.default({
      type: "success",
      message: t("Invitation sent, waiting for members to join."),
      duration: message.MESSAGE_DURATION.NORMAL
    });
  };
  return {
    t,
    isRoomLinkVisible,
    roomId,
    origin,
    pathname,
    isElectron: environment.isElectron,
    inviteLink,
    schemeLink,
    inviteBarTitle,
    onCopy,
    visibleInviteContentList,
    invitationFeatureDetails,
    showContacts,
    contactsConfirm,
    contacts,
    remoteEnteredUserList,
    showRoomInvite,
    userId,
    userName,
    conferenceInviteList,
    copyRoomIdAndRoomLink
  };
}
exports.default = useRoomInvite;
