import { defineComponent, ref, computed, onMounted, onUnmounted, unref, openBlock, createElementBlock, createVNode, withCtx, createCommentVNode } from "vue";
import IconButton from "../common/base/IconButton.vue.mjs";
import FullScreenIcon from "../common/icons/FullScreenIcon.vue.mjs";
import { exitFullScreen, setFullScreen } from "../../utils/utils.mjs";
import { useI18n } from "../../locales/index.mjs";
import { isVue27 } from "../../utils/constants.mjs";
import "../../services/main.mjs";
import { roomService } from "../../services/roomService.mjs";
import "@tencentcloud/tuiroom-engine-js";
import "mitt";
import "../../services/manager/roomActionManager.mjs";
import "@tencentcloud/tui-core";
const _hoisted_1 = {
  key: 0,
  class: "fullscreen-control-container"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "FullScreenControl",
  setup(__props) {
    const { t } = useI18n();
    const fullScreenConfig = roomService.getComponentConfig("FullScreen");
    const isFullScreen = ref(false);
    const title = computed(
      () => isFullScreen.value ? t("Exit") : t("Full screen")
    );
    function toggleScreen() {
      if (isFullScreen.value) {
        exitFullScreen();
      } else {
        if (isVue27) {
          const roomContainer = document.body;
          roomContainer && setFullScreen(roomContainer);
        } else {
          const roomContainer = document.getElementById("roomContainer");
          roomContainer && setFullScreen(roomContainer);
        }
      }
    }
    function handleFullScreenChange() {
      isFullScreen.value = !!document.fullscreenElement;
    }
    onMounted(() => {
      [
        "fullscreenchange",
        "webkitfullscreenchange",
        "mozfullscreenchange",
        "msfullscreenchange"
      ].forEach((item) => {
        window.addEventListener(item, handleFullScreenChange);
      });
    });
    onUnmounted(() => {
      [
        "fullscreenchange",
        "webkitfullscreenchange",
        "mozfullscreenchange",
        "msfullscreenchange"
      ].forEach((item) => {
        window.removeEventListener(item, handleFullScreenChange);
      });
    });
    return (_ctx, _cache) => {
      return unref(fullScreenConfig).visible ? (openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(IconButton, {
          "is-active": isFullScreen.value,
          title: title.value,
          onClickIcon: toggleScreen
        }, {
          default: withCtx(() => [
            createVNode(FullScreenIcon)
          ]),
          _: 1
        }, 8, ["is-active", "title"])
      ])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
