<template>
  <div class="container">
    <!-- 遮罩层区域 -->
    <div class="mask" @click="handleClose"></div>
    <!-- 弹窗内容区域 -->
    <div class="watch">
      <!-- 标题区域 -->
      <div class="title" :title="currentWatch">{{ currentWatch }}</div>

      <!-- 监控展示区域 -->
      <div class="iframe" id="videoDom5"></div>

      <!-- 关闭按钮区域 -->
      <div class="close" @click="handleClose"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from "vue";
// 引入监控数据
import { watchData } from "@/components/map/watchData";
// 引入监控相关的数据接口
import { getVedio } from "@/api/video/index";
// @ts-ignore
import WasmPlayer from "@easydarwin/easywasmplayer";

const props = defineProps(["currentWatch"]);
const $emit = defineEmits(["closeDialog"]);

// 监控实例
const player = ref();

onMounted(() => {
  // 获取监控视频地址
  getVideosData();
});

onUnmounted(() => {
  // 页面卸载时销毁WasmPlayer实例
  player.value?.destroy();
});

// 获取监控视频地址
const getVideosData = async () => {
  const Obj = watchData.find((ele) => ele.title === props.currentWatch);

  const res = await getVedio(Obj?.rtspaddr as string);
  player.value = new WasmPlayer(null, "videoDom5");

  player.value.play(res, 1);
};

// 点击关闭按钮回调
const handleClose = () => {
  $emit("closeDialog", false);
};
</script>

<style lang="scss" scoped>
.container {
  z-index: 9999;
  position: absolute;
  top: -151px;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 7072px;
  height: 1872px;
  background-color: rgba($color: #000000, $alpha: 0.4);

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 7072px;
    height: 1872px;
  }

  .watch {
    position: relative;
    padding: 0 50px;
    width: 748px;
    height: 600px;
    background-image: url(@/assets/images/75.png);
    background-size: 100% 100%;

    .title {
      padding: 0 20px;
      margin-left: 220px;
      margin-bottom: 90px;
      width: 224px;
      height: 46px;
      line-height: 46px;
      text-align: center;
      font-size: 35px;
      color: #ccffe6;
      font-family: "庞门正道标题体";
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .close {
      position: absolute;
      top: 10px;
      right: 6px;
      width: 42px;
      height: 42px;
      cursor: pointer;
      background-image: url(@/assets/images/12.png);
      background-size: 100% 100%;
    }
  }
}
</style>
