"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const room = require("tuikit-atomicx-vue3/room");
const type = require("../adapter/type.js");
const eventCenter = require("../utils/eventCenter.js");
const isJoiningRoom = vue.ref(false);
const joiningRoomId = vue.ref("");
const roomPasswordVisible = vue.ref(false);
const { t } = uikitBaseComponentVue3.useUIKit();
const { handleErrorWithModal } = room.useRoomModal();
const handleJoinRoomError = (error) => {
  let errorMessage = "";
  let useAlert = false;
  handleErrorWithModal(error);
  switch (error.code) {
    case TUIRoomEngine.TUIErrorCode.ERR_NEED_PASSWORD:
      roomPasswordVisible.value = true;
      return;
    case TUIRoomEngine.TUIErrorCode.ERR_WRONG_PASSWORD:
      uikitBaseComponentVue3.TUIToast.error({ message: t("Room.InvalidPassword") });
      return;
    case TUIRoomEngine.TUIErrorCode.ERR_ROOM_ID_NOT_EXIST:
      errorMessage = t("Room.RoomNotFound");
      useAlert = true;
      break;
    case TUIRoomEngine.TUIErrorCode.ERR_ROOM_USER_FULL:
      errorMessage = t("Room.RoomFull");
      useAlert = true;
      break;
    case TUIRoomEngine.TUIErrorCode.ERR_ROOM_ID_OCCUPIED:
      errorMessage = t("Room.RoomOccupied");
      useAlert = true;
      break;
    default:
      errorMessage = t("Room.JoinRoomError");
      console.error("Join room error:", error);
      eventCenter.eventCenter.emit(type.RoomEvent.ROOM_ERROR, error);
  }
  if (!errorMessage) {
    return;
  }
  if (useAlert) {
    uikitBaseComponentVue3.TUIMessageBox.alert({
      type: "error",
      modal: false,
      showClose: false,
      title: t("Room.Alert"),
      content: errorMessage,
      onConfirm: () => {
        eventCenter.eventCenter.emit(type.RoomEvent.ROOM_ERROR, error);
      }
    });
  } else {
    uikitBaseComponentVue3.TUIToast.error({ message: errorMessage });
  }
};
function useRoomLifeCycle() {
  return {
    isJoiningRoom,
    joiningRoomId,
    roomPasswordVisible,
    handleJoinRoomError
  };
}
exports.default = useRoomLifeCycle;
