"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 _hoisted_1 = { class: "header-h5" };
const _hoisted_2 = { class: "title" };
const _hoisted_3 = { class: "main-h5" };
const _hoisted_4 = { class: "room-info" };
const _hoisted_5 = { class: "form-item" };
const _hoisted_6 = { class: "form-item" };
const _hoisted_7 = { class: "form-label" };
const _hoisted_8 = { class: "form-input" };
const _hoisted_9 = { class: "room-settings" };
const _hoisted_10 = { class: "form-item toggle-item" };
const _hoisted_11 = { class: "form-label" };
const _hoisted_12 = { class: "form-item toggle-item" };
const _hoisted_13 = { class: "form-label" };
const _hoisted_14 = { class: "footer-h5" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "JoinRoomView",
  props: {
    cameraPreference: { type: Boolean, default: true },
    microphonePreference: { type: Boolean, default: true }
  },
  emits: ["join-room", "back", "camera-preference-change", "microphone-preference-change"],
  setup(__props, { emit: __emit }) {
    vue.useCssVars((_ctx) => ({
      "v0a779934": labelWidth.value
    }));
    const emit = __emit;
    const props = __props;
    const { t, theme, language } = uikitBaseComponentVue3.useUIKit();
    const { loginUserInfo } = room.useLoginState();
    const { getRoomInfo } = room.useRoomState();
    const roomId = vue.ref("");
    const openMicrophone = vue.ref(props.microphonePreference);
    const openCamera = vue.ref(props.cameraPreference);
    const loading = vue.ref(false);
    vue.watch(openMicrophone, (newVal) => {
      emit("microphone-preference-change", newVal);
    });
    vue.watch(openCamera, (newVal) => {
      emit("camera-preference-change", newVal);
    });
    const labelWidth = vue.computed(() => {
      if (language.value === "en-US") {
        return "115px";
      }
      return "80px";
    });
    const handleGoBack = () => {
      emit("back");
    };
    const checkRoomExist = async (id) => {
      try {
        await getRoomInfo({ roomId: id });
      } catch (error) {
        if (error && typeof error === "object" && "code" in error && error.code === TUIRoomEngine.TUIErrorCode.ERR_ROOM_ID_NOT_EXIST) {
          return false;
        }
      }
      return true;
    };
    const handleJoinRoom = async () => {
      loading.value = true;
      if (!roomId.value.trim()) {
        uikitBaseComponentVue3.TUIToast.error({ message: t("Room.RoomIdRequired") });
        return;
      }
      try {
        const exists = await checkRoomExist(roomId.value.trim());
        if (!exists) {
          uikitBaseComponentVue3.TUIMessageBox.alert({
            type: "error",
            modal: false,
            showClose: false,
            title: t("Room.Alert"),
            content: t("Room.RoomNotFound")
          });
          return;
        }
        emit("join-room", roomId.value.trim());
      } catch (error) {
        const errorMessage = error && typeof error === "object" && "message" in error ? String(error.message) : t("Room.JoinRoomError");
        uikitBaseComponentVue3.TUIToast.error({ message: errorMessage });
      } finally {
        loading.value = false;
      }
    };
    return (_ctx, _cache) => {
      var _a, _b;
      return vue.openBlock(), vue.createElementBlock("div", {
        class: vue.normalizeClass(["join-room-container-h5", vue.unref(theme)])
      }, [
        vue.createElementVNode("header", _hoisted_1, [
          vue.createVNode(vue.unref(uikitBaseComponentVue3.IconBack), {
            size: "22",
            class: "back-button",
            onClick: handleGoBack
          }),
          vue.createElementVNode("h1", _hoisted_2, vue.toDisplayString(vue.unref(t)("Button.JoinRoom")), 1),
          _cache[3] || (_cache[3] = vue.createElementVNode("div", { class: "header-placeholder" }, null, -1))
        ]),
        vue.createElementVNode("main", _hoisted_3, [
          vue.createElementVNode("div", _hoisted_4, [
            vue.createElementVNode("div", _hoisted_5, [
              vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIInput), {
                modelValue: roomId.value,
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => roomId.value = $event),
                label: vue.unref(t)("Room.RoomId"),
                class: "form-input",
                placeholder: vue.unref(t)("Room.EnterRoomId"),
                "max-length": "6"
              }, null, 8, ["modelValue", "label", "placeholder"])
            ]),
            vue.createElementVNode("div", _hoisted_6, [
              vue.createElementVNode("span", _hoisted_7, vue.toDisplayString(vue.unref(t)("User.Nickname")), 1),
              vue.createElementVNode("span", _hoisted_8, vue.toDisplayString(((_a = vue.unref(loginUserInfo)) == null ? void 0 : _a.userName) || ((_b = vue.unref(loginUserInfo)) == null ? void 0 : _b.userId)), 1)
            ])
          ]),
          vue.createElementVNode("div", _hoisted_9, [
            vue.createElementVNode("div", _hoisted_10, [
              vue.createElementVNode("span", _hoisted_11, vue.toDisplayString(vue.unref(t)("Room.OpenMicrophone")), 1),
              vue.createVNode(vue.unref(uikitBaseComponentVue3.TUISwitch), {
                modelValue: openMicrophone.value,
                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => openMicrophone.value = $event),
                size: "large"
              }, null, 8, ["modelValue"])
            ]),
            vue.createElementVNode("div", _hoisted_12, [
              vue.createElementVNode("span", _hoisted_13, vue.toDisplayString(vue.unref(t)("Room.OpenCamera")), 1),
              vue.createVNode(vue.unref(uikitBaseComponentVue3.TUISwitch), {
                modelValue: openCamera.value,
                "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => openCamera.value = $event),
                size: "large"
              }, null, 8, ["modelValue"])
            ])
          ])
        ]),
        vue.createElementVNode("div", _hoisted_14, [
          vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
            type: "primary",
            class: "join-button",
            loading: loading.value,
            onClick: handleJoinRoom
          }, {
            default: vue.withCtx(() => [
              vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Button.JoinRoom")), 1)
            ]),
            _: 1
          }, 8, ["loading"])
        ])
      ], 2);
    };
  }
});
exports.default = _sfc_main;
