"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const room = require("tuikit-atomicx-vue3/room");
const useRoomLifeCycle = require("../hooks/useRoomLifeCycle.js");
const eventCenter = require("../utils/eventCenter.js");
class Conference {
  constructor() {
    __publicField(this, "componentConfig", []);
  }
  login(params) {
    const { login } = room.useLoginState();
    return login({
      userId: params.userId,
      userSig: params.userSig,
      sdkAppId: params.sdkAppId
    });
  }
  async logout() {
    const { logout } = room.useLoginState();
    return logout();
  }
  getRoomEngine() {
    const roomEngine = room.useRoomEngine();
    if (!roomEngine) {
      console.warn("getRoomEngine failed, roomEngine is not exist");
    }
    return roomEngine;
  }
  on(eventType, callback) {
    eventCenter.eventCenter.on(eventType, callback);
  }
  off(eventType, callback) {
    eventCenter.eventCenter.off(eventType, callback);
  }
  async start({ roomId, roomType, options }) {
    const { createAndJoinRoom } = room.useRoomState();
    const {
      openLocalCamera,
      openLocalMicrophone,
      setCurrentCamera,
      setCurrentMicrophone,
      setCurrentSpeaker
    } = room.useDeviceState();
    const {
      roomName,
      isOpenCamera = false,
      isOpenMicrophone = false,
      defaultCameraId,
      defaultMicrophoneId,
      defaultSpeakerId,
      password
    } = options || {};
    const { isJoiningRoom, handleJoinRoomError } = useRoomLifeCycle.default();
    isJoiningRoom.value = true;
    try {
      await createAndJoinRoom({
        roomId,
        roomType: roomType || room.RoomType.Standard,
        options: {
          roomName,
          password
        }
      });
    } catch (error) {
      isJoiningRoom.value = false;
      handleJoinRoomError(error);
      throw error;
    }
    isJoiningRoom.value = false;
    if (defaultCameraId) {
      await setCurrentCamera({ deviceId: defaultCameraId });
    }
    if (defaultMicrophoneId) {
      await setCurrentMicrophone({ deviceId: defaultMicrophoneId });
    }
    if (defaultSpeakerId) {
      await setCurrentSpeaker({ deviceId: defaultSpeakerId });
    }
    if (isOpenCamera) {
      try {
        await openLocalCamera();
      } catch (error) {
        console.warn("Failed to open camera:", error);
      }
    }
    if (isOpenMicrophone) {
      try {
        await openLocalMicrophone();
      } catch (error) {
        console.warn("Failed to open microphone:", error);
      }
    }
  }
  async join({ roomId, roomType, options }) {
    const { joinRoom } = room.useRoomState();
    const {
      openLocalCamera,
      openLocalMicrophone,
      setCurrentCamera,
      setCurrentMicrophone,
      setCurrentSpeaker
    } = room.useDeviceState();
    const {
      isOpenCamera = false,
      isOpenMicrophone = false,
      defaultCameraId,
      defaultMicrophoneId,
      defaultSpeakerId,
      password
    } = options || {};
    const { isJoiningRoom, joiningRoomId, handleJoinRoomError } = useRoomLifeCycle.default();
    isJoiningRoom.value = true;
    joiningRoomId.value = roomId;
    try {
      await joinRoom({
        roomId,
        roomType: roomType || room.RoomType.Standard,
        password
      });
    } catch (error) {
      isJoiningRoom.value = false;
      handleJoinRoomError(error);
      return;
    }
    isJoiningRoom.value = false;
    joiningRoomId.value = "";
    if (defaultCameraId) {
      await setCurrentCamera({ deviceId: defaultCameraId });
    }
    if (defaultMicrophoneId) {
      await setCurrentMicrophone({ deviceId: defaultMicrophoneId });
    }
    if (defaultSpeakerId) {
      await setCurrentSpeaker({ deviceId: defaultSpeakerId });
    }
    if (isOpenCamera) {
      try {
        await openLocalCamera();
      } catch (error) {
        console.warn("Failed to open camera:", error);
      }
    }
    if (isOpenMicrophone) {
      try {
        await openLocalMicrophone();
      } catch (error) {
        console.warn("Failed to open microphone:", error);
      }
    }
  }
  async leave() {
    const { leaveRoom } = room.useRoomState();
    await leaveRoom();
  }
  async dismiss() {
    const { endRoom } = room.useRoomState();
    await endRoom();
  }
  setSelfInfo(options) {
    const { setSelfInfo } = room.useLoginState();
    return setSelfInfo(options);
  }
  setComponentConfig(config) {
    const index = this.componentConfig.findIndex((item) => item.componentName === config.componentName);
    if (index !== -1) {
      this.componentConfig[index] = config;
    } else {
      this.componentConfig.push(config);
    }
  }
  getComponentConfig(name) {
    return this.componentConfig.find((item) => item.componentName === name);
  }
  // public disableTextMessaging() {
  //   roomService.dataReportManager.reportCount(MetricsKey.disableTextMessaging);
  //   roomService.setComponentConfig({ ChatControl: { visible: false } });
  // }
  // public disableScreenSharing() {
  //   roomService.dataReportManager.reportCount(MetricsKey.disableScreenSharing);
  //   roomService.setComponentConfig({ ScreenShare: { visible: false } });
  // }
  // public enableWatermark() {
  //   roomService.dataReportManager.reportCount(MetricsKey.enableWatermark);
  //   roomService.waterMark.toggleWatermark(true);
  // }
  // public enableVirtualBackground() {
  //   roomService.dataReportManager.reportCount(
  //     MetricsKey.enableVirtualBackground
  //   );
  //   roomService.setComponentConfig({ VirtualBackground: { visible: true } });
  // }
  // public hideFeatureButton(name: FeatureButton) {
  //   roomService.dataReportManager.reportCount(MetricsKey.hideFeatureButton);
  //   roomService.setComponentConfig({ [name]: { visible: false } });
  // }
  // public replaceFriendList(userList: Array<any>) {
  //   return roomService.scheduleConferenceManager.replaceFriendList(userList);
  // }
  // public setUserListSortComparator(comparator: Comparator<UserInfo>) {
  //   roomService.userManager.setUserListSortComparator(comparator);
  // }
  // public setStreamListSortComparator(comparator: Comparator<StreamInfo>) {
  //   roomService.userManager.setStreamListSortComparator(comparator);
  // }
  // public setParticipants(
  //   participants: Array<{
  //     userName: string;
  //     userId: string;
  //     avatarUrl: string;
  //   }>
  // ) {
  //   const list = participants.map(item => {
  //     const { userId, userName, avatarUrl } = item;
  //     return {
  //       userID: userId,
  //       profile: { userID: userId, nick: userName, avatar: avatarUrl },
  //     };
  //   });
  //   roomService.scheduleConferenceManager.replaceFriendList(list);
  // }
}
const conference = new Conference();
exports.conference = conference;
