<template>
  <div :class="classes">
    <div class="student-video" title="点击放大播放" @click="toLargeView">
      <flv-media
        ref="ThirdViewVideo"
        :live-url="data.liveUrl"
        v-if="data.liveUrl"
      ></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-audio', { 'is-active': !this.muted }]"
            @click="toMuted"
          >
            <i class="icon icon-audio"></i>
          </div>
          <div class="student-info-time">
            <i class="icon icon-alarm-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="primary" size="mini" round @click="toDetail"
            >详情</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 {};
      },
    },
  },
  data() {
    return {
      muted: true,
    };
  },
  computed: {
    classes() {
      return [
        "invigilation-student",
        {
          "invigilation-student-breach": !this.data.breachStatus,
          "invigilation-student-netbreak": this.data.statusCode === "BREAK_OFF",
        },
      ];
    },
  },
  methods: {
    toDetail() {
      this.$router.push({
        name: "WarningDetail",
        params: { recordId: this.data.examRecordId },
      });
    },
    toLargeView() {
      this.muted = true;
      this.$emit("muted", false);
      this.$refs.ThirdViewVideo.destroyPlayer();
      this.$refs.InvigilationStudentMediaDialog.open();
    },
    toMuted() {
      console.log(this.muted);
      const nextMuted = !this.muted;
      this.$emit("muted", nextMuted);
      const res = this.mutedPlayer(nextMuted);
      if (res) this.muted = nextMuted;
    },
    mutedPlayer(muted) {
      return this.$refs.ThirdViewVideo.mutedPlayer(muted);
    },
    dialogClose() {
      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-time {
      background-color: #fe5863 !important;
    }
  }

  &-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;
  cursor: pointer;

  // &::before {
  //   content: "";
  //   display: block;
  //   position: absolute;
  //   top: 50%;
  //   left: 50%;
  //   width: 32px;
  //   height: 20px;
  //   margin-left: -16px;
  //   margin-top: -10px;
  //   background-image: url(../../../assets/icon-video.png);
  //   background-size: 100% 100%;
  // }
}
.student-info {
  position: relative;
  padding: 0 10px 10px;

  &-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
  }
  &-audio {
    display: inline-block;
    vertical-align: middle;
    width: 24px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    background: #abb8c9;
    border-radius: 50%;
    margin-right: 5px;
    cursor: pointer;
    &:hover {
      background: #1886fe;
    }

    &.is-active {
      background: #1886fe;
    }

    .icon {
      width: 14px;
      height: 12px;
      margin-top: -2px;
    }
  }
  &-time {
    display: inline-block;
    vertical-align: middle;
    height: 24px;
    padding: 4px 12px;
    border-radius: 12px;
    background: #abb8c9;
    color: #fff;
    line-height: 16px;
    font-size: 12px;
    > 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;
  }
}
</style>
