<template>
  <div class="video">
    <video v-if="isvideo" :id=" 'a' + time" style="width:100%;height:100%"></video>
    <img v-else :src="info.img" style="width:100%;height:100%" alt="">
    <div class="liveinfo">
          <div class="left">
              <div>
                  <img src="@/static/images/livelesson.png" alt="" class="icon">
                  <span>{{lan.$t('xiabanyayu')}}</span>
              </div>
              <div>
                  <img src="@/static/images/livewatch.png" alt="" class="icon">
                  <span>{{info.tlanguage}}</span>
              </div>
              <div>
                  <img src="@/static/images/livetimetake.png" alt="" class="icon">
                  <span>{{info.livetime}}min</span>
              </div>
                    <div>
                  <img src="@/static/images/shoucang.png" alt="" class="icon">
                  <span class="score">{{info.score}}{{lan.$t('fen')}}</span>
              </div>
          </div>
          <div style="display: flex">
            <div class="right" @click="bianji" v-if="info.livestatus == 0">
              {{lan.$t('bianjixinxi')}}
            </div>
            <div class="right" @click="kaishi" v-if="info.livestatus == 0">
              {{lan.$t('kaishizhibo')}}
            </div>
          </div>
          
      </div>
  </div>
</template>
<style lang="scss" scoped>
.video {
  width: 976px;
  height: 563px;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  > video {
    width: 100%;
    height: 505px;
  }
  .liveinfo{
        flex-shrink: 0;
        display: flex;
        justify-content: space-between;
        height: 58px;
        align-items: center;
        background-color: #fff;
        .left{
            display: flex;
            color: #121212;
            font-size: 13px;
            margin-left: 29px;
            .score{
              color: #D22C2E;
              font-size: 13px;
            }
            >div{
                margin-right: 57px;
            }
            .icon{
                width: 25px;
                height:24px;
                margin-right: 6px;

            }
        }
        .right{
            width: 74px;
            height: 29px;
            border:1px solid #08AE98;
            border-radius: 3px;
            margin-right: 29px;
            color: #08AE98;
            cursor: pointer;
            font-size: 13px;
            line-height: 29px;
            font-weight: bold;
            text-align: center;
        }
      }
}
</style>
<script lang="ts">
import { livestart } from '@/api';
import router from '@/router';
import { useI18n } from '@/utils/i18n';
import { defineComponent, onUpdated, ref, watch } from "vue";
import { onBeforeRouteLeave } from 'vue-router';

export default defineComponent({
  props:{
    info: Object
  },
  setup(props) {
    const lan: any = useI18n();
    console.log(props.info);
    function bianji(){
      if(props.info != undefined){
        router.push("/mine/webcast?id=" + props.info.liveid)
      }
    }
    // todo 修改后报错
    function kaishi(){
      if(props.info != undefined){
        const id = props.info.liveid;
        livestart(id).then(()=>{
            router.push("/live/liveing?id=" + id)
        })
      }
    }
    const time = ref(new Date().getTime())
    let play: any;
    const isvideo = ref(true);
    
    watch(()=> props.info,()=>{
      if(props.info){
        console.log(props.info)

          if(props.info.fileid != '0' || props.info.vodid != ''){
            play = window.TCPlayer('a' + time.value, { 
                fileID: (props.info.livestatus == 0 ? props.info.fileid : props.info.vodid),
                appID: '1303872925' 
            });
          }else{
            isvideo.value = false;
          }
          
        }
    })
    onBeforeRouteLeave((to, from, next) => {
      console.log(121)
      if(play){
        play.dispose()
      }
        next()
    })
    // const liveinfo = ref(props.liveinfo)
    return {
      bianji,
      kaishi,
      lan,
      time,
      isvideo
    }
  }
});
</script>