<template>
  <div @click="router.push(`/videoPlay?id=${item.id}`)">
    <div class="status">
      <span>预计{{ dayjs(item.startTime).format("MM-DD") }}</span>
      <div class="time">
        <span>{{ dayjs(item.startTime).format("HH:mm") }}开播</span>
        <p class="sub" @click.stop="setSubLiveVideo(item)">
          <img
            v-if="item.isSubscribe !== 1"
            src="@/assets/images/status2.png"
            alt=""
            srcset=""
          />
          <img v-else src="@/assets/images/status3.png" />
          <i>{{ item.isSubscribe !== 1 ? "预约" : "已预约" }}</i>
        </p>
      </div>
    </div>
    <div class="content">
      <h4>{{ item.title }}</h4>
      <p>{{ item.viewPoint }}</p>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from "vue";
import { useRouter } from "vue-router";
import dayjs from "dayjs";
import { subLiveVideo } from "@/api/video";
import { showToast } from "vant";
const router = useRouter();
defineProps({
  item: {
    type: Object,
    default: () => ({}),
  },
});

const setSubLiveVideo = async (item) => {
  let ret = await subLiveVideo({
    id: item.id,
    option: item.isSubscribe === 1 ? 2 : 1,
  });
  if (ret.code === 0) {
    item.isSubscribe = item.isSubscribe === 1 ? 2 : 1;
    if (item.isSubscribe === 1) {
      showToast("预约成功，开播前将会提醒您！");
    } else {
      showToast("已取消预约！");
    }
  }
};
</script>
<style scoped lang="scss">
.status {
  display: flex;
  align-items: center;
  background: url(../../../../assets/images/point1.png) no-repeat left center;
  background-size: 20px 20px;
  font-size: 24px;
  padding-left: 36px;
  height: 40px;
  .time {
    display: flex;
    align-items: center;
    margin-left: 24px;
  }
  p {
    display: flex;
    align-items: center;
    margin-left: 14px;
    img {
      display: block;
      width: 24px;
      height: 24px;
    }
    i {
      color: rgb(46, 120, 250);
      font-size: 24px;
      font-style: normal;
      font-weight: 500;
      margin-left: 4px;
    }
  }
}
.content {
  text-align: left;
  padding: 16px 24px 32px;
  border-left: 1px solid rgba(230, 230, 230, 1);
  margin-left: 8px;
  h4 {
    color: rgb(0, 0, 0);
    font-size: 32px;
    font-style: normal;
    font-weight: 500;
    line-height: 48px;
    margin-bottom: 8px;
  }
  p {
    color: rgb(102, 102, 102);
    font-size: 28px;
    font-style: normal;
    font-weight: 400;
    line-height: 44px;
  }
}
.sub {
  display: flex;
  align-items: center;
}
</style>
