<template>
  <div class="activities-page">
    <!-- 横幅图片区域 -->
    <div class="hero-banner">
      <div class="banner-image-container">
        <!-- 实际图片 -->
        <img
          v-if="hasBannerImage"
          :src="bannerImageSrc"
          alt="活动横幅"
          class="banner-image"
        />
        <!-- 图片占位区域 -->
        <div v-else class="banner-placeholder">
          <div class="placeholder-content">
            <div class="placeholder-icon">🖼️</div>
            <div class="placeholder-text">横幅图片占位</div>
            <div class="placeholder-desc">请提供横幅图片</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <div class="container">
        <!-- 全部活动区域 -->
        <section class="all-activities">
          <h2 class="section-title">全部活动</h2>
          
          <!-- 活动网格 -->
          <div v-if="loading" class="loading-grid">
            <div v-for="i in 6" :key="i" class="loading-card">
              <div class="loading-shimmer"></div>
            </div>
          </div>

          <div v-else class="activities-grid">
            <div
              v-for="activity in activities"
              :key="activity.id"
              class="activity-card"
            >
              <div class="card-header">
                <div class="card-image">
                  <img
                    src="/images/activity/活动图1.png"
                    alt="活动图片"
                    class="activity-image"
                  />
                </div>
              </div>

              <div class="card-body">
                <!-- 状态标签 -->
                <div class="status-badge">
                  <span class="status-text">进行中</span>
                </div>

                <!-- 课程标题 -->
                <h3 class="course-main-title">{{ activity.courseTitle }}</h3>

                <!-- 课程副标题 -->
                <p class="course-subtitle-text">{{ activity.subtitle }}</p>

                <!-- 课程详细信息 -->
                <div class="course-details">
                  <div class="detail-item">
                    <span class="detail-label">活动时间：</span>
                    <span class="detail-value">{{ activity.schedule.replace('开课时间：', '') }}</span>
                  </div>
                  <div class="detail-item">
                    <span class="detail-label">活动类型：</span>
                    <span class="detail-value">激励类活动</span>
                  </div>
                  <div class="detail-item">
                    <span class="detail-label">已报名：</span>
                    <span class="detail-value">{{ activity.students.replace('已报名：', '') }}</span>
                  </div>
                </div>

                <!-- 查看详情按钮 -->
                <div class="card-footer">
                  <button class="detail-btn" @click="viewDetail(activity.id)">
                    查看活动
                  </button>
                </div>
              </div>
            </div>
          </div>
        </section>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'

// 加载状态
const loading = ref(true)

// 横幅图片路径 - 您可以在这里设置图片路径
const bannerImageSrc = ref('/images/activity/活动切图-轮播区.png')

// 检查是否有横幅图片
const hasBannerImage = computed(() => bannerImageSrc.value.trim() !== '')

// 活动数据
const activities = ref([
  {
    id: 1,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  },
  {
    id: 2,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  },
  {
    id: 3,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  },
  {
    id: 4,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  },
  {
    id: 5,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  },
  {
    id: 6,
    title: '计算机二级',
    subtitle: 'C语言讲练综合班',
    courseTitle: '计算机二级C语言程序设计证书',
    schedule: '开课时间：2025.07.26-2025.09.28',
    duration: '适合年级：高校本科生',
    students: '已报名：1468/2000',
    price: '免费'
  }
])

// 查看详情
const viewDetail = (id: number) => {
  console.log('查看活动详情:', id)
  // 这里可以跳转到活动详情页面
  // router.push(`/activity/${id}`)
}

// 设置横幅图片的方法（供后续使用）
// const setBannerImage = (imagePath: string) => {
//   bannerImageSrc.value = imagePath
// }

// 模拟数据加载
onMounted(() => {
  setTimeout(() => {
    loading.value = false
  }, 800)

  // 示例：如果您有图片路径，可以在这里设置
  // setBannerImage('/images/activities-banner.jpg')
})
</script>

<style scoped>
.activities-page {
  min-height: 100vh;
  background: #f8f9fa;
}

/* 横幅图片区域 */
.hero-banner {
  width: 100%;
  position: relative;
  overflow: hidden;
}

.banner-image-container {
  width: 100%;
  height: 400px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.banner-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.banner-placeholder::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
  opacity: 0.3;
}

.placeholder-content {
  text-align: center;
  color: white;
  position: relative;
  z-index: 1;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.8;
}

.placeholder-text {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}

.placeholder-desc {
  font-size: 16px;
  opacity: 0.8;
}

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

/* 主要内容区域 */
.main-content {
  padding: 80px 0;
}

.section-title {
  font-size: 28px;
  font-weight: 600;
  color: #333;
  text-align: center;
  margin: 0 0 50px 0;
}

/* 活动网格 */
.activities-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
}

.activity-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
}

.activity-card:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  transform: translateY(-4px);
}

/* 卡片头部 */
.card-header {
  position: relative;
  height: 180px;
  overflow: hidden;
  border-radius: 12px 12px 0 0;
}

.card-image {
  width: 100%;
  height: 100%;
  position: relative;
}

.activity-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.year-badge {
  position: absolute;
  top: 15px;
  left: 20px;
  background: #9ACD32;
  color: #333;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.course-title {
  font-size: 18px;
  font-weight: 600;
  color: white;
  margin-bottom: 4px;
  position: relative;
  z-index: 1;
}

.course-subtitle {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
  position: relative;
  z-index: 1;
}



/* 卡片主体 */
.card-body {
  padding: 20px;
}

/* 状态标签 */
.status-badge {
  margin-bottom: 12px;
}

.status-text {
  display: inline-block;
  background: #FF6B35;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

/* 课程标题 */
.course-main-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0 0 8px 0;
  line-height: 1.4;
}

/* 课程副标题 */
.course-subtitle-text {
  font-size: 14px;
  color: #FF6B35;
  margin: 0 0 16px 0;
  line-height: 1.4;
}

/* 课程详细信息 */
.course-details {
  margin-bottom: 20px;
}

.detail-item {
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.detail-label {
  color: #999;
}

.detail-value {
  color: #666;
}

/* 卡片底部 */
.card-footer {
  text-align: center;
}

.detail-btn {
  width: 100%;
  padding: 12px 20px;
  background: #f5f5f5;
  color: #666;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.detail-btn:hover {
  background: #4A90E2;
  color: white;
  transform: translateY(-1px);
}

/* 加载状态 */
.loading-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
}

.loading-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  height: 320px;
}

.loading-shimmer {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* 动画效果 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.banner-image-container {
  animation: fadeInUp 0.8s ease-out;
}

.activity-card {
  animation: fadeInUp 0.6s ease-out;
  animation-fill-mode: both;
}

.activity-card:nth-child(1) { animation-delay: 0.1s; }
.activity-card:nth-child(2) { animation-delay: 0.2s; }
.activity-card:nth-child(3) { animation-delay: 0.3s; }
.activity-card:nth-child(4) { animation-delay: 0.4s; }
.activity-card:nth-child(5) { animation-delay: 0.5s; }
.activity-card:nth-child(6) { animation-delay: 0.6s; }

/* 响应式设计 */
@media (max-width: 1024px) {
  .activities-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }

  .banner-image-container {
    height: 350px;
  }

  .placeholder-icon {
    font-size: 40px;
  }

  .placeholder-text {
    font-size: 20px;
  }

  .card-header {
    height: 160px;
  }
}

@media (max-width: 768px) {
  .activities-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .banner-image-container {
    height: 300px;
  }

  .placeholder-icon {
    font-size: 36px;
  }

  .placeholder-text {
    font-size: 18px;
  }

  .placeholder-desc {
    font-size: 14px;
  }

  .main-content {
    padding: 40px 0;
  }

  .container {
    padding: 0 16px;
  }

  .card-header {
    height: 140px;
  }
}

@media (max-width: 480px) {
  .banner-image-container {
    height: 250px;
  }

  .placeholder-icon {
    font-size: 32px;
  }

  .placeholder-text {
    font-size: 16px;
  }

  .placeholder-desc {
    font-size: 12px;
  }

  .feature-tags {
    justify-content: center;
  }
}
</style>
