import screenfull from "screenfull"
import { ref } from "vue"
import { ElMessage } from "element-plus"

export const isFullscreen = ref(false)
/**
 * 全屏
 * @isScreenfull 为true的时候，是全屏的时候 不关闭
 * @isErr 为false 不提示
 */
export const handleFullscreen = (isScreenfull = false, isErr = true) => {
   if (!screenfull.isEnabled) {
      isErr &&
         ElMessage({
            message: "当前浏览器不支持全屏！",
            type: "warning"
         })
      return
   }
   if (isFullscreen.value && isScreenfull) {
      return
   }
   screenfull.toggle()
}

if (screenfull.isEnabled) {
   screenfull.on("change", () => {
      isFullscreen.value = screenfull.isFullscreen
   })
}

// 禁用f11
document.addEventListener("keydown", function (event) {
   if (event.key === "F11") {
      event.preventDefault()
      handleFullscreen()
   }
})
