<template>
  <div class="full-view-header">
    <div class="esc-back" @click="$emit('back')">
      <span class="icon icon-back"></span>
      <span class="esc">ESC返回</span>
    </div>
    <div class="filter-form">
      <el-form inline>
        <el-form-item class="exam-select">
          <div @click="$refs.ExamBatchDialog.open()">
            <el-input
              v-model="curExamBatch.label"
              placeholder="请选择批次"
              suffix-icon="el-icon-arrow-down"
              readonly
            ></el-input>
          </div>
        </el-form-item>
        <el-form-item class="exam-room-select">
          <el-select v-model="filter.roomCode" placeholder="考场">
            <el-option
              v-for="item in examRooms"
              :key="item.roomCode"
              :label="item.roomName"
              :value="item.roomCode"
            >
              <span>{{ item.roomName }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="viewingAngles.length" class="media-source-select">
          <el-select v-model="filter.monitorVideoSource" placeholder="视频源">
            <el-option
              v-for="item in viewingAngles"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            >
              <span>{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="current-date-time">
      <TextClock :showIcon="false" :showApm="false" />
    </div>
    <!-- 考试批次选择 -->
    <exam-batch-dialog
      @confirm="examChange"
      ref="ExamBatchDialog"
    ></exam-batch-dialog>
  </div>
</template>

<script>
import { examActivityRoomList } from "@/api/invigilation";
import { VIDEO_SOURCE_TYPE } from "@/constant/constants";
import ExamBatchDialog from "../ExamBatchDialog";
import TextClock from "../../common/TextClock";
export default {
  name: "RealtimeMonitoringFullHeader",
  components: {
    TextClock,
    ExamBatchDialog,
  },
  data() {
    return {
      /** 筛选条件 */
      filter: {
        examId: "",
        roomCode: "",
        monitorVideoSource: "",
        monitorStatus: "",
      },
      /** 考场列表 */
      examRooms: [],
      /** 视频源 */
      viewingAngles: [],
      /** 当前考试批次 */
      curExamBatch: {},
    };
  },
  watch: {
    filter: {
      handler() {
        this.$emit("filterChange", this.filter);
      },
      deep: true,
    },
    "filter.examId": {
      handler: "getExamRooms",
      immediate: true,
    },
  },
  methods: {
    examChange(examBatch) {
      if (!examBatch) return;
      this.curExamBatch = examBatch;
      if (examBatch.monitorVideoSource) {
        this.viewingAngles = examBatch.monitorVideoSource
          .split(",")
          .map((item) => {
            return {
              code: item,
              name: VIDEO_SOURCE_TYPE[item],
            };
          });
      } else {
        this.viewingAngles = [];
      }
      this.filter.examId = examBatch.id;
      this.filter.monitorStatus = examBatch.monitorStatus;
      this.filter.monitorVideoSource = this.viewingAngles?.[0]?.code ?? "";
    },
    async getExamRooms() {
      this.examRooms = [];
      if (!this.curExamBatch.id) return;
      const res = await examActivityRoomList(this.curExamBatch.id);
      this.examRooms = res.data.data.examRooms ?? [];
      this.filter.roomCode = this.examRooms[0]?.roomCode;
    },
  },
};
</script>

<style lang="scss" scoped>
.full-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  .esc-back {
    display: flex;
    align-items: center;
    cursor: pointer;
    &:hover {
      filter: brightness(1.2);
    }
    .icon {
      width: 24px;
      height: 24px;
    }
    .esc {
      font-size: 14px;
      color: #fff;
      font-weight: bold;
      margin-left: 10px;
    }
  }
  ::v-deep .filter-form {
    .exam-select {
      .el-input {
        min-width: 450px;
        .el-input__icon {
          line-height: 40px;
        }
      }
    }
    .exam-room-select {
      width: 200px;
    }
    .media-source-select {
      width: 160px;
    }
    .el-form-item {
      margin-bottom: 0;
    }
    .el-input {
      .el-input__icon {
        line-height: 32px;
      }
      .el-input__inner {
        height: 36px;
        background: rgba(66, 66, 69, 0);
        color: #a1a8b3;
        border-radius: 10px;
        border: 2px solid #3f444d;
      }
    }
  }
  .current-date-time {
    font-size: 12px;
    font-weight: bold;
    color: #a1a8b3;
  }
}
</style>
