<template>
  <div style="background-color: #f0f2f5; padding-bottom: 20px; min-height: 100%; " >
    <div style="padding: 20px; background-color: #fff;">
      课程视频详情
    </div>
    <div class="contentx" >
      <div class="desct">
        小节信息
      </div>
      <el-descriptions title="" :column="3" border>
        <el-descriptions-item label="视频ID"  >
          <span v-if="item!=null">{{item.videoId}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="视频标题" >
          <span v-if="item!=null">{{item.title}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="封面图" >
          <el-popover v-if="item!=null"
            placement="right"
            title=""
            trigger="hover">
            <img slot="reference" :src="item.thumbnail" width="50px">
            <img :src="item.thumbnail" style="max-width: 150px;">
          </el-popover>
        </el-descriptions-item>
        <el-descriptions-item label="视频描述" >
          <span v-if="item!=null">{{item.description}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="时长" >
            <span v-if="item!=null">{{formatDuration(item.duration)}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="课程排序" >
            <span v-if="item!=null">{{item.courseSort}}</span>
        </el-descriptions-item>

        <el-descriptions-item label="创建时间" >
            <span v-if="item!=null">{{item.createTime}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="审核时间" >
            <span v-if="item!=null">{{item.auditTime}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="备注" >
            <span v-if="item!=null">{{item.remark}}</span>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div class="contentx" v-if="item">
      <div class="desct">
        视频内容
      </div>
      <div style="display: flex; justify-content: center; align-items: center;">
          <div style="display: grid; place-items: center;" v-if="item.videoUrl!=null">
             <video  :src="item.videoUrl" controls style="max-width: 400px; max-height: 400px;"></video>
          </div>
      </div>
    </div>
    <div class="contentx" v-if="item">
      <div class="desct">
        题目内容
      </div>
      <div>
        <div style="display: grid; " v-if="item.questionBankId!=null">
          <el-table border width="100%" style="margin-top:5px;"  :data="item.questionBankList">
            <el-table-column label="问题" align="center" prop="title">
              <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" :content="scope.row.title" placement="top">
                  <div style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; text-overflow: ellipsis;">
                    <span>{{ scope.row.title }}</span>
                  </div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column label="类别" align="center" prop="type">
              <template slot-scope="scope">
                <dict-tag :options="typeOptions" :value="scope.row.type"/>
              </template>
            </el-table-column>
            <el-table-column label="答案" align="center" prop="answer" />
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getUserCourseVideo} from "@/api/course/userCourseVideo";
  export default {
    name: "userCourseVideoDetails",
    data() {
      return {
        typeOptions:[],
        packageTypeOptions: [],
        diseaseTypeOptions: [],
        packageSubTypeOptions:[],
        item:null,
        packageItem:null,
        productJson:[],
        courseIdOptions: [],
        // 视频状态 1：草稿，2：待审核，3：发布字典
        statusOptions: [],
        // 是否展示字典
        orOptions: [],
        // 来源 1 用户 2 后台字典
        sourceOptions: [],
        // 删除标志字典
        isDelOptions: [],
        isAuditOptions:[],
        specShowOptions:[]
      }
    },
    created() {
      this.getDicts("sys_course_temp_type").then(response => {
        this.typeOptions = response.data;
      });
    },
    methods: {
      formatDuration(seconds) {
        if (seconds === null || seconds === undefined) {
          return '未上传视频'; // 或者您可以根据具体需求返回其他默认值
        }
        const hours = Math.floor(seconds / 3600);
        const minutes = Math.floor((seconds % 3600) / 60);
        const remainingSeconds = seconds % 60;

        const formattedHours = hours > 0 ? hours.toString() + ':' : '';
        const formattedMinutes = minutes.toString().padStart(2, '0');
        const formattedSeconds = remainingSeconds.toString().padStart(2, '0');

        return `${formattedHours}${formattedMinutes}:${formattedSeconds}`;
      },
      getDetails(videoId) {
        console.log(videoId);
        this.item=null;
        getUserCourseVideo(videoId).then(response => {
          this.item = response.data;
        });
      },
    }
  }
</script>

<style>
  .contentx{
      height: 100%;
      background-color: #fff;
      padding: 0px 20px 20px;


      margin: 20px;
  }
  .el-descriptions-item__label.is-bordered-label{
    font-weight: normal;
  }
  .el-descriptions-item__content {
    max-width: 150px;
    min-width: 100px;
  }
  .desct{
      padding-top: 20px;
      padding-bottom: 20px;
      color: #524b4a;
      font-weight: bold;
    }

</style>
