<template>
  <div class="video-wrap">
    <VideoHeader :detail="detail" />
    <div class="content">
      <h3>距离直播开始</h3>
      <div class="time">{{ formTime }}</div>
      <img :src="detail.imgUrl" alt="" srcset="" />
      <div>
        <button class="active" v-if="isSubscribe === 1">
          <img src="@/assets/images/status6.png" alt="" srcset="" />
          已预约
        </button>

        <button v-else @click="setSubLiveVideo" :disabled="disableSub">
          <img src="@/assets/images/status5.png" alt="" srcset="" />
          预约直播
        </button>
        <p>{{ subscribeUserCount }}人已预约</p>
      </div>
    </div>
    <VideoFooter
      ref="videoFooterRef"
      :detail="detail"
      :activityObj="activityObj"
      :informMsgList="informMsgList"
      :isSpeak="isSpeak"
      @sendMsg="sendMsg"
      @closeActivity="closeActivity"
      @clearScreenFn="clearScreenFn"
    />
  </div>
</template>

<script setup>
import { ref, defineProps } from "vue";
import { useRoute } from "vue-router";
import useCountDown from "@/hooks/useCountDown";
import { subLiveVideo } from "@/api/video";
import VideoHeader from "../components/VideoHeader.vue";
import VideoFooter from "../components/VideoFooter.vue";
const route = useRoute();
const props = defineProps({
  detail: {
    type: Object,
    default: () => ({}),
  },
  liveStatus: {
    type: Number,
  },
  isSpeak: {
    // 是否关闭互动
    type: Boolean,
    default: false,
  },
  activityObj: {
    type: Object,
    default: () => ({}),
  },
  informMsgList: {
    // 聊天互动信息
    type: Array,
    default: () => [],
  },
  showPlayBtn: {
    type: Boolean,
    default: false,
  },
  online: {
    type: Number,
  },
  closeActivity: {
    type: Function,
  },
  sendMsg: {
    type: Function,
  },
});
const isSubscribe = ref(props.detail.isSubscribe); // 是否预约
const subscribeUserCount = ref(props.detail.subscribeUserCount); // 预约人数
const { formTime, startDownTime } = useCountDown();

startDownTime(props.detail.startTime);

const disableSub = ref(false);
const setSubLiveVideo = async () => {
  disableSub.value = true;
  let ret = await subLiveVideo({
    id: props.detail.id,
    option: isSubscribe.value === 1 ? 2 : 1,
    saleUserId: route.query.saleUserId,
  }).catch(() => {
    disableSub.value = false;
  });
  disableSub.value = false;
  if (ret.code === 0) {
    isSubscribe.value = isSubscribe.value === 1 ? 2 : 1;
    subscribeUserCount.value = ret.data.count;
  }
};

// const emit = defineEmits(["updateVideoDetail"]);
</script>
<style scoped lang="scss">
.video-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url(../../../assets/images/video-bg.png) no-repeat center;
  background-size: cover;
}
.content {
  position: absolute;
  top: 180px;
  left: 10px;
  right: 10px;
  padding: 0 20px;
  bottom: 524px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  h3 {
    color: rgb(255, 255, 255);
    text-align: center;
    font-size: 32px;
    font-weight: 400;
    line-height: 56px;
  }
  .time {
    color: #fff;
    text-align: center;
    font-size: 40px;
    font-style: normal;
    font-weight: 400;
    line-height: 56px;
    margin-bottom: 20px;
  }
  img {
    display: block;
    border-radius: 24px;
    height: 320px;
    width: 100%;
  }
  button {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
    width: 248px;
    border-radius: 45px;
    border: 1px solid #979797;
    color: rgb(255, 255, 255);
    font-size: 28px;
    font-weight: 500;
    background: none;
    margin: 32px auto 32px;
    img {
      width: 48px;
      height: 48px;
      margin-right: 8px;
    }
    &.active {
      color: rgba(240, 46, 24, 1);
      border: 1px solid var(---, #f02e18);
    }
  }
  p {
    color: rgb(153, 153, 153);
    text-align: center;
    font-size: 28px;
    font-weight: 500;
    line-height: 32px;
  }
}
.footer {
  position: absolute;
  bottom: 50px;
  left: 20px;
  right: 20px;
  display: flex;
  input {
    flex: 1;
    text-align: left;
    color: rgb(179, 179, 179);
    font-size: 24px;
    font-weight: 500;
    line-height: 64px;
    opacity: 0.5;
    border-radius: 32px;
    background: rgba(0, 0, 0, 0.3);
    padding-left: 20px;
  }
  .share {
    background: url(../../../assets/images/share.png) no-repeat center;
    background-size: cover;
    width: 64px;
    height: 64px;
    margin-left: 20px;
  }
}
</style>
