<template>
  <div class="course-center">
    <div class="course-header">
      <h2>课程中心</h2>
      <div class="course-categories">
        <div 
          class="category-tab" 
          v-for="category in categories" 
          :key="category.id"
          :class="{ active: activeCategory === category.id }"
          @click="activeCategory = category.id"
        >
          {{ category.name }}
        </div>
      </div>
    </div>

    <div class="course-grid">
      <div class="course-card" v-for="course in filteredCourses" :key="course.id" @click="viewCourse(course)">
        <div class="course-cover">
          <img :src="course.cover" :alt="course.title" />
          <div class="course-duration">{{ course.duration }}</div>
        </div>
        <div class="course-info">
          <h3>{{ course.title }}</h3>
          <p class="course-description">{{ course.description }}</p>
          <div class="course-meta">
            <span class="course-teacher">
              <i class="icon">👨‍🏫</i>
              {{ course.teacher }}
            </span>
            <span class="course-students">
              <i class="icon">👥</i>
              {{ course.students }} 人学习
            </span>
          </div>
          <div class="course-footer">
            <div class="course-rating">
              <span class="rating-stars">★★★★★</span>
              <span class="rating-score">{{ course.rating }}</span>
            </div>
            <el-button type="primary" size="small">开始学习</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElButton } from 'element-plus';

const router = useRouter();
const activeCategory = ref('all');
const courses = ref<any[]>([]);

const categories = [
  { id: 'all', name: '全部课程' },
  { id: 'party-history', name: '党史教育' },
  { id: 'theory', name: '理论学习' },
  { id: 'policy', name: '政策解读' },
  { id: 'ethics', name: '道德修养' }
];

const filteredCourses = computed(() => {
  if (activeCategory.value === 'all') return courses.value;
  return courses.value.filter(course => course.category === activeCategory.value);
});

onMounted(() => {
  // TODO: 加载课程数据
});

function viewCourse(course: any) {
  router.push(`/study/course/${course.id}`);
}
</script>

<style lang="scss" scoped>
.course-center {
  padding: 40px;
}

.course-header {
  margin-bottom: 32px;
  
  h2 {
    font-size: 24px;
    font-weight: 600;
    color: #141F38;
    margin-bottom: 20px;
  }
}

.course-categories {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.category-tab {
  padding: 8px 20px;
  background: #f5f5f5;
  border-radius: 20px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
  
  &:hover {
    background: #ffe6e6;
    color: #C62828;
  }
  
  &.active {
    background: #C62828;
    color: white;
  }
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.course-card {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
  
  &:hover {
    border-color: #C62828;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px);
  }
}

.course-cover {
  position: relative;
  width: 100%;
  height: 200px;
  background: #f5f5f5;
  
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.course-duration {
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 4px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 4px;
  font-size: 12px;
}

.course-info {
  padding: 20px;
  
  h3 {
    font-size: 18px;
    font-weight: 600;
    color: #141F38;
    margin-bottom: 12px;
    line-height: 1.4;
  }
}

.course-description {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.course-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #999;
  
  .icon {
    margin-right: 4px;
  }
}

.course-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

.course-rating {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rating-stars {
  color: #FFB400;
  font-size: 14px;
}

.rating-score {
  font-size: 14px;
  font-weight: 600;
  color: #141F38;
}
</style>

