<template>
  <div class="container">
    <div class="course-grid">
      <div v-for="course in courses" :key="course.id" class="course-card">
        <div class="course-image">
          <img :src="course.cover" alt="课程图片">
          <div class="live-badge">即将开播</div>
          <div class="live-time">{{ course.startTime }}</div>
        </div>
        <div class="course-info">
          <div class="course-title">{{ course.title }}</div>
          <div class="course-footer">
            <div class="course-tag">
              <img :src="course.cover" alt="讲师头像">
              <!-- <img src="../pic/images/1.png" alt="讲师头像"> -->
              {{ course.publisherName }}
            </div>
            <button class="book-btn" :class="{ active: course.booked }" @click="toggleBook(course.id)">预约</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import zhiboApi from '@/api/zhiboApi';
import { ref } from 'vue';
const courses = ref([]);


function formatTime(queryType) {
  zhiboApi.selectZhibo(queryType).then(resp => {
    if(resp.data){
      courses.value = resp.data.list;
      console.log(courses.value);
    }
  })
}

formatTime();

</script>


<style scoped>
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.course-card {
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
  min-width: 250px;
  height: 230px;
}

.course-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
}

.course-image {
  position: relative;
  height: 150px;
  background-color: #333;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.course-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.live-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: bold;
  z-index: 2;
}

.live-time {
  position: absolute;
  top: calc(50% + 30px);
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.course-info {
  padding: 5px; /* 减少内边距 */
}

.course-title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 5px; /* 减少底部边距 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 28px;
  text-align: left;
}

.course-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 5px; /* 减少顶部边距 */
}

.course-tag {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #666;
}

.course-tag img {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-right: 5px;
}

.book-btn {
  background-color: #ff6b00;
  color: white;
  border: none;
  border-radius: 20px;
  padding: 4px 15px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s; /* 添加动态效果 */
}

.book-btn:hover {
  background-color: #ff8c33;
  transform: scale(1.05); /* 悬停时放大按钮 */
}

.book-btn.active {
  background-color: #ff8c33;
  transform: scale(1.05); /* 预约成功后保持放大效果 */
}
</style>
