"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 index$4 = require("../../components/CameraButtonH5/index.vue2.js");
const index$5 = require("../../components/JoinRoomButtonH5/index.vue2.js");
const index$2 = require("../../components/LanguageButton/index.vue2.js");
const index = require("../../components/LoginUserInfoH5/index.vue2.js");
const index$3 = require("../../components/MicButtonH5/index.vue2.js");
const index$6 = require("../../components/StartRoomButtonH5/index.vue2.js");
const index_vue_vue_type_script_setup_true_lang = require("../../components/SwitchCameraButtonH5/index.vue.js");
const index$1 = require("../../components/ThemeButton/index.vue2.js");
const _hoisted_1 = { class: "header-h5" };
const _hoisted_2 = { class: "user-info-section" };
const _hoisted_3 = { class: "header-actions" };
const _hoisted_4 = { class: "main-h5" };
const _hoisted_5 = { class: "preview-card" };
const _hoisted_6 = { class: "camera-preview-area" };
const _hoisted_7 = { class: "camera-preview-area-header" };
const _hoisted_8 = { class: "attention-info" };
const _hoisted_9 = {
  key: 0,
  class: "off-camera-info"
};
const _hoisted_10 = { class: "media-controls-overlay" };
const _hoisted_11 = { class: "action-buttons" };
const _hoisted_12 = { class: "footer-h5" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "PreviewView",
  emits: ["logout", "create-room", "join-room", "camera-preference-change", "microphone-preference-change"],
  setup(__props, { emit: __emit }) {
    const emit = __emit;
    const { t, theme, language } = uikitBaseComponentVue3.useUIKit();
    const {
      isCameraTesting,
      isMicrophoneTesting,
      isCameraTestLoading,
      startCameraTest,
      startMicrophoneTest,
      stopCameraTest,
      stopMicrophoneTest
    } = room.useDeviceState();
    const { handleErrorWithModal } = room.useRoomModal();
    vue.watch(isMicrophoneTesting, (newVal) => {
      emit("microphone-preference-change", newVal);
    });
    vue.watch(isCameraTesting, (newVal) => {
      emit("camera-preference-change", newVal);
    });
    const handleCreateRoom = async () => {
      emit("create-room");
    };
    const handleJoinRoom = async () => {
      emit("join-room");
    };
    function handleLogout() {
      emit("logout");
    }
    vue.onMounted(() => {
      const roomPreviewVideo = document.getElementById("room-preview-video");
      TUIRoomEngine.once("ready", async () => {
        if (roomPreviewVideo) {
          try {
            await startCameraTest({ view: roomPreviewVideo });
          } catch (error) {
            handleErrorWithModal(error);
          }
        }
        try {
          await startMicrophoneTest();
        } catch (error) {
          handleErrorWithModal(error);
        }
      });
    });
    vue.onBeforeUnmount(() => {
      stopCameraTest();
      stopMicrophoneTest();
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        class: vue.normalizeClass(["home-container-h5", vue.unref(theme)])
      }, [
        vue.createElementVNode("header", _hoisted_1, [
          vue.createElementVNode("div", _hoisted_2, [
            vue.createVNode(index.default, { onLogout: handleLogout })
          ]),
          vue.createElementVNode("div", _hoisted_3, [
            vue.createVNode(index$1.default),
            vue.createVNode(index$2.default)
          ])
        ]),
        vue.createElementVNode("main", _hoisted_4, [
          vue.createElementVNode("div", _hoisted_5, [
            vue.createElementVNode("div", _hoisted_6, [
              vue.createElementVNode("div", _hoisted_7, [
                vue.createVNode(index_vue_vue_type_script_setup_true_lang.default)
              ]),
              _cache[0] || (_cache[0] = vue.createElementVNode("div", {
                id: "room-preview-video",
                class: "video-preview"
              }, null, -1)),
              vue.createElementVNode("div", _hoisted_8, [
                !vue.unref(isCameraTesting) && !vue.unref(isCameraTestLoading) ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_9, vue.toDisplayString(vue.unref(t)("Off Camera")), 1)) : vue.createCommentVNode("", true),
                vue.unref(isCameraTestLoading) ? (vue.openBlock(), vue.createBlock(vue.unref(uikitBaseComponentVue3.IconLoading), {
                  key: 1,
                  size: "36",
                  class: "loading"
                })) : vue.createCommentVNode("", true)
              ]),
              vue.createElementVNode("div", _hoisted_10, [
                vue.createVNode(index$3.default, {
                  showDescription: false,
                  customStyle: { backgroundColor: "transparent", color: "#fff" }
                }),
                vue.createVNode(index$4.default, {
                  cameraTestContainer: "room-preview-video",
                  showDescription: false,
                  customStyle: { backgroundColor: "transparent", color: "#fff" }
                })
              ])
            ])
          ]),
          vue.createElementVNode("div", _hoisted_11, [
            vue.createVNode(index$5.default, {
              class: "primary-button",
              onJoinRoom: handleJoinRoom
            }),
            vue.createVNode(index$6.default, {
              class: "primary-button",
              onStartRoom: handleCreateRoom
            })
          ])
        ]),
        vue.createElementVNode("footer", _hoisted_12, [
          vue.createElementVNode("div", {
            class: vue.normalizeClass(["brand-logo", vue.unref(theme), vue.unref(language)])
          }, null, 2)
        ])
      ], 2);
    };
  }
});
exports.default = _sfc_main;
