<template>
  <div class="wrapper">
    <!-- :poster="videoImg"视频封面 -->
    <video id="my-player" :key="current.public_video_url" class="video-js" controls autoplay preload="auto" ref="myVideo">
      <source :src="current.public_video_url" type="video/mp4">
    </video>
    <!-- 视频名称列表布局 -->
    <div class="video-wrapper">
      <div class="flex items-center justify-between h-10">
        <div class="text-base font-medium">剧名: <span class="ml-2 text-lg font-bold text-dark-600">{{
          props.primary.name }}</span></div>
        <el-tooltip placement="top">
          <template #content> 如需批量下载，则多选目标集数，点击下载按钮即可<br /> </template>
          <download v-if="videoChoose.length > 0" :urls="videoChooseUrls" :fileName="props.primary.name"></download>
        </el-tooltip>
      </div>
      <mytabs :meta="meta" v-if="meta.total" @change="handChange">
        <template v-slot:content>
          <el-checkbox-group v-model="videoChoose" size="large" class="flex items-center">
            <el-checkbox border class="video-item" @change="videoShow(source)" v-for="(source, index) in videoUrlList"
              :key="index" :label="source">
              {{ source.series_sequence }}
            </el-checkbox>
          </el-checkbox-group>
        </template>
      </mytabs>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { videoStockEpisodeList } from '@/api/video/index'
const myVideo = ref()
const videoChoose = ref([])
const changeForm = ref({ page: 1, limit: 5 })
const props = defineProps({
  primary: String | Number,
});
const videoUrlList = ref([])
if (props.primary) {

}
const meta = ref({})

const current = ref({})
const videoChooseUrls = ref([])
const initVideoList = (params: object) => {
  videoStockEpisodeList({ video_id: props.primary.id, ...params }).then(res => {
    videoUrlList.value = res.data;
    meta.value = { limit: res.limit, total: res.total }
  })
}


const handChange = (e) => {
  console.log(e, 'handChange');
  changeForm.value.page = Number(e.page);
  initVideoList(changeForm.value);
}
const videoShow = (source: object) => {
  console.log(source);
  current.value = videoChoose.value.find(el => el.public_video_url == source.public_video_url) ?? {}
  videoChooseUrls.value = videoChoose.value
  console.log(videoChooseUrls.value, 'videoChooseUrls.value');
}

onMounted(() => {
  initVideoList(changeForm.value)
})
</script>


<style lang="scss" scoped>
.wrapper {
  padding-left: 40px;
  margin-top: 30px;
  display: flex;
  width: 100%;
}

//播放器样式
video#my-player.video-js {
  width: 30%;
  height: 580px;
  background-color: #000;
}

.video-wrapper {
  width: 100%;
  margin-left: 40px;

  .video-item {
    margin: 6px;

    :deep(.el-checkbox__input .el-checkbox__inner) {
      display: none;
    }
  }

  :deep(.el-checkbox-group .el-checkbox.is-checked) {
    background-color: #2566ff;
  }

  :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: #fff
  }
}
</style>
