import { defineComponent, computed, watch, onMounted, onUnmounted, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, unref, createVNode, createCommentVNode, isRef } from "vue";
import DeviceSelect from "./DeviceSelect.vue.mjs";
import VideoProfile from "./VideoProfile.vue.mjs";
import TuiSwitch from "./base/TuiSwitch.vue.mjs";
import { useBasicStore } from "../../stores/basic.mjs";
import { useI18n } from "../../locales/index.mjs";
import useGetRoomEngine from "../../hooks/useRoomEngine.mjs";
import { TRTCVideoMirrorType, TRTCVideoRotation, TRTCVideoFillMode } from "@tencentcloud/tuiroom-engine-js";
import { isMobile, isElectron } from "../../utils/environment.mjs";
import { storeToRefs } from "pinia";
const _hoisted_1 = { class: "item-setting" };
const _hoisted_2 = { class: "title" };
const _hoisted_3 = {
  key: 0,
  class: "item-setting"
};
const _hoisted_4 = { class: "title" };
const _hoisted_5 = { class: "item-setting" };
const _hoisted_6 = { class: "title" };
const _hoisted_7 = { class: "mirror-container" };
const _hoisted_8 = {
  key: 1,
  class: "item-setting"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "VideoSettingTab",
  props: {
    withPreview: { type: Boolean },
    withMore: { type: Boolean },
    withMirror: { type: Boolean },
    theme: {}
  },
  setup(__props) {
    const roomEngine = useGetRoomEngine();
    const props = __props;
    const basicStore = useBasicStore();
    const { isLocalStreamMirror } = storeToRefs(basicStore);
    const themeClass = computed(
      () => props.theme ? `tui-theme-${props.theme}` : ""
    );
    watch(isLocalStreamMirror, async (val) => {
      var _a;
      const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud();
      if (!isMobile) {
        await (trtcCloud == null ? void 0 : trtcCloud.setLocalRenderParams({
          mirrorType: val ? TRTCVideoMirrorType.TRTCVideoMirrorType_Enable : TRTCVideoMirrorType.TRTCVideoMirrorType_Disable,
          rotation: TRTCVideoRotation.TRTCVideoRotation0,
          fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill
        }));
      }
    });
    const { t } = useI18n();
    function handleMoreCameraSetting() {
      basicStore.setShowSettingDialog(true);
      basicStore.setActiveSettingTab("video");
    }
    if (props.withPreview) {
      onMounted(async () => {
        var _a, _b;
        (_a = roomEngine.instance) == null ? void 0 : _a.startCameraDeviceTest({ view: "test-camera-preview" });
        if (isElectron) {
          const trtcCloud = (_b = roomEngine.instance) == null ? void 0 : _b.getTRTCCloud();
          await (trtcCloud == null ? void 0 : trtcCloud.setLocalRenderParams({
            mirrorType: isLocalStreamMirror.value ? TRTCVideoMirrorType.TRTCVideoMirrorType_Enable : TRTCVideoMirrorType.TRTCVideoMirrorType_Disable,
            rotation: TRTCVideoRotation.TRTCVideoRotation0,
            fillMode: TRTCVideoFillMode.TRTCVideoFillMode_Fill
          }));
        }
      });
      onUnmounted(() => {
        var _a;
        (_a = roomEngine.instance) == null ? void 0 : _a.stopCameraDeviceTest();
      });
    }
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(["video-tab", themeClass.value])
      }, [
        createElementVNode("div", _hoisted_1, [
          createElementVNode("span", _hoisted_2, toDisplayString(unref(t)("Camera")), 1),
          createVNode(DeviceSelect, { "device-type": "camera" })
        ]),
        _ctx.withPreview ? (openBlock(), createElementBlock("div", _hoisted_3, [
          createElementVNode("span", _hoisted_4, toDisplayString(unref(t)("Preview")), 1),
          _cache[1] || (_cache[1] = createElementVNode("div", { class: "video-preview-container" }, [
            createElementVNode("div", {
              id: "test-camera-preview",
              class: "video-preview"
            })
          ], -1))
        ])) : createCommentVNode("", true),
        createElementVNode("div", _hoisted_5, [
          createElementVNode("span", _hoisted_6, toDisplayString(unref(t)("Resolution")), 1),
          createVNode(VideoProfile)
        ]),
        createElementVNode("div", _hoisted_7, [
          createElementVNode("span", null, toDisplayString(unref(t)("Mirror")), 1),
          createVNode(TuiSwitch, {
            modelValue: unref(isLocalStreamMirror),
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(isLocalStreamMirror) ? isLocalStreamMirror.value = $event : null)
          }, null, 8, ["modelValue"])
        ]),
        _ctx.withMore ? (openBlock(), createElementBlock("div", _hoisted_8, [
          createElementVNode("div", {
            class: "item",
            onClick: handleMoreCameraSetting
          }, toDisplayString(unref(t)("More Camera Settings")), 1)
        ])) : createCommentVNode("", true)
      ], 2);
    };
  }
});
export {
  _sfc_main as default
};
