<template>
  <div :class="classes">
    <div class="student-video" title="点击放大播放" @click="toLargeView">
      <flv-media
        ref="ThirdViewVideo"
        :live-url="data.liveUrl"
        :max-retry-count="maxRetryCount"
        @muted-change="mutedChange"
      ></flv-media>
    </div>
    <div class="student-info">
      <div class="student-info-header">
        <h6 class="student-info-name">
          <span>{{ data.name }}</span
          ><i class="icon icon-net-break"></i>
        </h6>
        <div class="student-info-tips">
          <div class="student-info-time">
            <i
              :class="['icon', isNetbreak ? 'icon-clock-danger' : 'icon-clock']"
            ></i>
            <span>{{ data.remainTime }}</span>
          </div>
        </div>
      </div>
      <div class="student-info-body">
        <div class="student-info-content">
          <p>{{ data.identity }}</p>
          <p>答题进度：{{ data.progress || 0 }}%</p>
        </div>
        <div class="student-info-detail">
          <el-button type="text" size="small" @click="toDetail"
            >{{ detailName }} <i class="el-icon-arrow-right"></i
          ></el-button>
        </div>
      </div>
    </div>

    <!-- InvigilationStudentMediaDialog -->
    <InvigilationStudentMediaDialog
      ref="InvigilationStudentMediaDialog"
      :data="data"
      destroy-on-close
      @close="dialogClose"
    />
  </div>
</template>

<script>
import FlvMedia from "./FlvMedia";
import InvigilationStudentMediaDialog from "./InvigilationStudentMediaDialog.vue";

export default {
  name: "invigilation-student",
  components: { FlvMedia, InvigilationStudentMediaDialog },
  props: {
    data: {
      type: Object,
      default() {
        return {};
      },
    },
    showType: {
      type: String,
      default: "invigilation",
    },
    maxRetryCount: {
      type: Number,
      default: 3,
    },
    detailName: {
      type: String,
      default: "详情",
    },
  },
  data() {
    return {
      muted: true,
    };
  },
  computed: {
    isNetbreak() {
      return this.data.statusCode === "BREAK_OFF";
    },
    classes() {
      return [
        "invigilation-student",
        {
          "invigilation-student-breach": !this.data.breachStatus,
          "invigilation-student-netbreak": this.isNetbreak,
        },
      ];
    },
  },
  methods: {
    toDetail() {
      if (this.showType === "invigilation") {
        this.$router.push({
          name: "WarningDetail",
          params: { examRecordId: this.data.examRecordId },
        });
      } else {
        this.$router.push({
          name: "PatrolWarningDetail",
          params: { examRecordId: this.data.examRecordId },
        });
      }
    },
    toLargeView() {
      this.$emit("muted-change");
      this.$emit("video-view-change", true);
      this.$refs.ThirdViewVideo.destroyPlayer();
      this.$refs.InvigilationStudentMediaDialog.open();
    },
    mutedChange() {
      this.$emit("muted-change");
    },
    mutedPlayer(muted) {
      this.$refs.ThirdViewVideo.mutedPlayer(muted);
    },
    dialogClose() {
      this.$emit("video-view-change", false);
      this.$refs.ThirdViewVideo.reloadVideo();
    },
  },
};
</script>

<style lang="scss" scoped>
.invigilation-student {
  padding: 10px;
  position: relative;
  margin-bottom: 20px;
  border: 1px solid #f0f4f9;
  border-radius: 10px;

  &-breach {
    &::before {
      content: "";
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      width: 50px;
      height: 50px;
      background-image: url(../../../assets/bg-discipline.png);
      background-size: 100% 100%;
      z-index: 99;
    }
    // &::after {
    //   content: "";
    //   display: block;
    //   position: absolute;
    //   top: 4px;
    //   right: 4px;
    //   width: 12px;
    //   height: 12px;

    //   border: 2px solid #fff;
    //   border-radius: 50%;
    //   background: #fe5863;
    //   z-index: 99;
    // }
  }

  &-netbreak {
    .icon-net-break {
      display: inline-block !important;
    }
    .student-info-time {
      background-color: rgba(254, 88, 99, 0.1) !important;
      color: rgba(254, 88, 99, 1);
    }
  }

  &-none {
    height: 100%;
    background: #606060;
    border-radius: 6px;
    font-size: 50px;
    text-align: center;
    padding-top: 90px;
    color: #202b4b;
  }
}
.student-video {
  height: 150px;
  border-radius: 6px;
  background: #626a82;
  margin-bottom: 15px;
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.student-info {
  position: relative;

  &-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
  }
  &-time {
    display: inline-block;
    vertical-align: middle;
    height: 24px;
    padding: 0 12px;
    border-radius: 5px;
    background: #f0f4f9;
    color: #626a82;
    line-height: 24px;
    font-size: 14px;
    > i {
      margin-right: 5px;
      width: 12px;
      height: 12px;
    }
    > span {
      display: inline-block;
      vertical-align: middle;
    }
  }

  &-name {
    font-size: 18px;
    margin-bottom: 0;
    > .icon {
      margin-top: -4px;
      margin-left: 8px;
      display: none;
    }
  }
  &-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  &-content {
    flex-grow: 2;
    overflow: hidden;
    > p {
      font-size: 14px;
      font-weight: 400;
      color: #626a82;
      line-height: 20px;
      margin: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  &-detail {
    margin-left: 5px;
    flex-grow: 0;
    flex-shrink: 0;

    .el-button {
      padding: 0;
      font-size: 14px;
    }
  }
}
</style>
