<template>
  <div class="nvr-timeselect">
    <div class="head">
      <div class="line"></div>
      <div class="title">视频下载</div>
      <span class="tips">（请先拖动进度条，再点击选取时间按钮）</span>
    </div>

    <div class="timeselect">
      <div class="time-picker">
        开始时间：
        <el-input
          v-model="startTime"
          style="width: 160px; margin: 0 8px"
          disabled
          placeholder="拖动进度条选择时间"
        />
        <el-tooltip
          class="picker-tooltip"
          effect="dark"
          content="请先拖动进度条，再点击按钮选择时间"
          placement="top"
        >
          <img
            @click="callSetTime(true)"
            style="cursor: pointer"
            src="@\assets\icons\icon-picker.png"
            alt=""
          />
        </el-tooltip>
        <el-icon class="icon-refresh" :size="18">
          <Refresh @click="startTime = ''" />
        </el-icon>
      </div>
      <div class="time-picker">
        结束时间：
        <el-input
          v-model="endTime"
          style="width: 160px; margin: 0 8px"
          disabled
          placeholder="拖动进度条选择时间"
        />
        <el-tooltip
          class="picker-tooltip"
          effect="dark"
          content="请先拖动进度条，再点击按钮选择时间"
          placement="top"
        >
          <img
            @click="callSetTime(false)"
            style="cursor: pointer"
            src="@\assets\icons\icon-picker.png"
            alt=""
          />
        </el-tooltip>
        <el-icon class="icon-refresh" :size="18">
          <Refresh @click="endTime = ''" />
        </el-icon>
      </div>

      <el-button
        type="primary"
        :loading="isCallingDownload"
        :disabled="!startTime.length || !endTime.length"
        @click="nvrDownload"
        >下 载</el-button
      >
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { ElInput } from 'element-plus';
  import { Refresh } from '@element-plus/icons-vue';
  import { ElIcon, ElTooltip } from 'element-plus';

  const isCallingDownload = ref(false);
  const startTime = ref('');
  const endTime = ref('');

  const emit = defineEmits(['setTime', 'downloadNvr']);

  const callSetTime = (isStart: boolean) => {
    emit('setTime', isStart);
  };

  const nvrDownload = () => {
    emit('downloadNvr');
  };
  const clearTime = () => {
    startTime.value = '';
    endTime.value = '';
  };

  defineExpose({ isCallingDownload, startTime, endTime, clearTime });
</script>

<style scoped lang="scss">
  .nvr-timeselect {
    width: 50%;
    height: 100vh;
    background-color: #ffffff;
    .head {
      display: flex;
      align-items: center;
      margin-left: 8px;
      margin-top: 14px;
      .line {
        width: 4px;
        height: 16px;
        background: #1890ff;
      }
      .title {
        font-size: 14px;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.88);
        line-height: 20px;
        margin-left: 8px;
      }
      .tips {
        font-weight: 400;
        font-size: 10px;
        color: #909399;
        line-height: 14px;
      }
    }
    .timeselect {
      padding: 12px 22px 0 22px;
      .time-picker {
        margin-bottom: 12px;
        display: flex;
        align-items: center;
        .picker-tooltip {
          width: 110px;
          margin-top: 10px;

          img {
            display: inline;
            margin-left: 20px;
          }
        }
        .icon-refresh {
          color: #1890ff;
          margin: 0 8px;
          cursor: pointer;
        }
      }
    }
  }
</style>
