<template>
  <div class="modal">
    <div class="title">
      <div class="title-1">{{ props.nowPreviewRecord.name }}</div>
      <div class="title-2">
        {{
          props.nowPreviewRecord.createTime +
          ' ' +
          props.nowPreviewRecord.size +
          ' ' +
          props.nowPreviewRecord.id
        }}
      </div>
    </div>
    <div class="closeButton">
      <CloseOutlined @click="closeModal" style="font-size: 25px; color: white" />
    </div>
    <div class="mainBody">
      <div class="imgOrVideo">
        <!-- 图片 -->
        <div
          class="imageDiv"
          v-if="
            props.nowPreviewRecord.objectKey && props.nowPreviewRecord.objectKey.includes('jpeg')
          "
        >
          <PreviewImage
            :nowPreviewRecord="props.nowPreviewRecord"
            :previewRecordList="props.previewRecordList"
            @chooseNowPreviewRecord="chooseNowPreviewRecord"
            @handleSuccessPreview="handleSuccessPreview"
            @setHideOrShowTextboxFlag="setHideOrShowTextboxFlag"
          />
        </div>
        <!-- 视频 -->
        <div
          class="videoDiv"
          v-if="
            props.nowPreviewRecord.objectKey && props.nowPreviewRecord.objectKey.includes('mp4')
          "
        >
          <PreviewVideo
            :nowPreviewRecord="props.nowPreviewRecord"
            :previewRecordList="props.previewRecordList"
            @chooseNowPreviewRecord="chooseNowPreviewRecord"
            @handleSuccessPreview="handleSuccessPreview"
          />
        </div>
      </div>
      <div class="information">
        <PreviewImageInformation
          v-if="
            props.nowPreviewRecord.objectKey && props.nowPreviewRecord.objectKey.includes('jpeg')
          "
          :nowPreviewRecord="props.nowPreviewRecord"
          :previewRecordList="props.previewRecordList"
          @chooseNowPreviewRecord="chooseNowPreviewRecord"
          @handleSuccessPreview="handleSuccessPreview"
          :hideOrShowTextboxFlag="hideOrShowTextboxFlag"
          @openPathModal="openPathModal"
        />
        <PreviewVideoInformation
          v-if="
            props.nowPreviewRecord.objectKey && props.nowPreviewRecord.objectKey.includes('mp4')
          "
          :nowPreviewRecord="props.nowPreviewRecord"
          :previewRecordList="props.previewRecordList"
          @chooseNowPreviewRecord="chooseNowPreviewRecord"
          @handleSuccessPreview="handleSuccessPreview"
        />
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { CloseOutlined } from '@ant-design/icons-vue';
  import {
    PreviewImage,
    PreviewImageInformation,
    PreviewVideo,
    PreviewVideoInformation,
  } from './preview';

  const props = defineProps(['nowPreviewRecord', 'previewRecordList']);
  const emits = defineEmits([
    'closeModal',
    'chooseNowPreviewRecord',
    'handleSuccessPreview',
    'openPathModal',
  ]);

  const hideOrShowTextboxFlag = ref(true);
  function setHideOrShowTextboxFlag(value) {
    hideOrShowTextboxFlag.value = value;
  }

  // 选择
  function chooseNowPreviewRecord(value) {
    emits('chooseNowPreviewRecord', value);
  }
  // 刷新表格
  function handleSuccessPreview(record = null) {
    emits('handleSuccessPreview', record);
  }
  // 关闭弹窗
  function closeModal() {
    document.body.style.cursor = 'default';
    emits('closeModal');
  }
  // 打开路径弹窗
  function openPathModal(value) {
    emits('openPathModal', value);
  }
</script>
<style lang="less" scoped>
  .modal {
    width: 100%;
    height: 100%;

    // 页面不能被选中
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE/Edge */
    user-select: none;
  }
  .title {
    pointer-events: none;
    position: absolute;
    top: 10px;
    left: 15px;
    z-index: 100;

    .title-1 {
      font-size: 20px;
      color: #ffffff;
    }
    .title-2 {
      font-size: 16px;
      color: #f0f3f3;
    }
  }
  .closeButton {
    position: absolute;
    top: 10px;
    right: 15px;
    z-index: 50;
  }
  .mainBody {
    width: 100%;
    height: 100%;
    display: flex;
    position: absolute;
    top: 0px;
    left: 0px;

    .imgOrVideo {
      width: 80%;
      height: 100%;
      background: #101010;

      .imageDiv {
        // display: flex;
        // align-items: center;
        position: relative;
        justify-content: center;
        width: 100%;
        height: 100%;
      }

      .videoDiv {
        position: relative;
        justify-content: center;
        width: 100%;
        height: 100%;
      }
    }

    .information {
      position: relative;
      width: 20%;
      height: 100%;
      background: #1c1c1c;
    }
  }
</style>
