"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js");
const index$1 = require("./StreamPlay/index.vue.js");
const index$2 = require("./StreamCover/index.vue.js");
const index = require("./LocalScreenView/index.vue.js");
const basic = require("../../../stores/basic.js");
const vDblTouch = require("../../../directives/vDblTouch.js");
const _sfc_main = /* @__PURE__ */ Vue.defineComponent({
  __name: "StreamRegionPC",
  props: {
    streamInfo: {},
    isEnlarge: { type: Boolean, default: false },
    aspectRatio: {},
    isNeedPlayStream: { type: Boolean, default: true },
    observerViewInVisible: { type: Boolean }
  },
  emits: ["room-dblclick"],
  setup(__props) {
    const props = __props;
    const basicStore = basic.useBasicStore();
    const isLocalScreen = Vue.computed(
      () => props.streamInfo && props.streamInfo.userId === basicStore.userId && props.streamInfo.streamType === TUIRoomEngine.TUIVideoStreamType.kScreenStream
    );
    const streamRegionContainerRef = Vue.ref();
    const streamStyle = Vue.ref({ width: "", height: "" });
    const widthRatio = Vue.computed(() => {
      if (!props.aspectRatio || props.aspectRatio.indexOf(":") < 0) {
        return 0;
      }
      return Number(props.aspectRatio.split(":")[0]);
    });
    const heightRatio = Vue.computed(() => {
      if (!props.aspectRatio || props.aspectRatio.indexOf(":") < 0) {
        return 0;
      }
      return Number(props.aspectRatio.split(":")[1]);
    });
    function handleStreamRegionSize() {
      if (!streamRegionContainerRef.value) {
        return;
      }
      const containerWidth = streamRegionContainerRef.value.offsetWidth;
      const containerHeight = streamRegionContainerRef.value.offsetHeight;
      let width = containerWidth;
      let height = containerHeight;
      if (widthRatio.value && heightRatio.value) {
        const scaleWidth = containerWidth / widthRatio.value;
        const scaleHeight = containerHeight / heightRatio.value;
        if (scaleWidth > scaleHeight) {
          width = containerHeight / heightRatio.value * widthRatio.value;
          height = containerHeight;
        }
        if (scaleWidth <= scaleHeight) {
          width = containerWidth;
          height = containerWidth / widthRatio.value * heightRatio.value;
        }
      }
      streamStyle.value.width = `${width}px`;
      streamStyle.value.height = `${height}px`;
    }
    const ro = new ResizeObserver(() => {
      handleStreamRegionSize();
    });
    Vue.onMounted(() => {
      ro.observe(streamRegionContainerRef.value);
    });
    Vue.onBeforeUnmount(() => {
      ro.unobserve(streamRegionContainerRef.value);
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", {
        class: "stream-region-container",
        ref_key: "streamRegionContainerRef",
        ref: streamRegionContainerRef
      }, [
        Vue.withDirectives((Vue.openBlock(), Vue.createElementBlock("div", {
          class: "stream-region",
          onDblclick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("room-dblclick")),
          style: Vue.normalizeStyle(streamStyle.value)
        }, [
          isLocalScreen.value ? (Vue.openBlock(), Vue.createBlock(index.default, {
            key: 0,
            streamInfo: _ctx.streamInfo,
            isMiniRegion: !_ctx.isEnlarge
          }, null, 8, ["streamInfo", "isMiniRegion"])) : (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 1 }, [
            Vue.createVNode(index$1.default, {
              streamInfo: _ctx.streamInfo,
              isEnlarge: _ctx.isEnlarge,
              isNeedPlayStream: _ctx.isNeedPlayStream,
              observerViewInVisible: _ctx.observerViewInVisible
            }, null, 8, ["streamInfo", "isEnlarge", "isNeedPlayStream", "observerViewInVisible"]),
            Vue.createVNode(index$2.default, { streamInfo: _ctx.streamInfo }, null, 8, ["streamInfo"])
          ], 64))
        ], 36)), [
          [
            Vue.unref(vDblTouch.default),
            () => {
              _ctx.$emit("room-dblclick");
            }
          ]
        ])
      ], 512);
    };
  }
});
exports.default = _sfc_main;
