<template>
  <view class="discover-container">
    <!-- 搜索框 -->
    <view class="search-section">
      <view class="search-box">
        <uni-icons type="search" size="18" color="#999"></uni-icons>
        <input class="search-input" placeholder="python · html · java..." />
      </view>
    </view>

    <!-- 轮播图 -->
    <view class="banner-section">
      <swiper class="banner-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
        <swiper-item v-for="(item, index) in bannerList" :key="index">
          <view class="banner-item" :style="{ backgroundColor: item.bgColor }">
            <view class="banner-content">
              <view class="banner-text">
                <text class="banner-title">{{ item.title }}</text>
                <text class="banner-subtitle">{{ item.subtitle }}</text>
                <view class="banner-btn">{{ item.btnText }}</view>
              </view>
              <image class="banner-image" :src="item.image" mode="aspectFit"></image>
            </view>
          </view>
        </swiper-item>
      </swiper>
    </view>

    <!-- 功能模块 -->
    <view class="function-section">
      <view class="function-row">
        <view class="function-item" v-for="(item, index) in functionList.slice(0, 5)" :key="index" @click="handleFunctionClick(item)">
          <view class="function-icon">
            <image :src="item.icon" mode="aspectFit"></image>
          </view>
          <text class="function-text">{{ item.name }}</text>
          <view v-if="item.badge" class="function-badge">{{ item.badge }}</view>
        </view>
      </view>
      <view class="function-row">
        <view class="function-item" v-for="(item, index) in functionList.slice(5, 10)" :key="index" @click="handleFunctionClick(item)">
          <view class="function-icon" :style="{ backgroundColor: item.bgColor }">
            <image :src="item.icon" mode="aspectFit"></image>
          </view>
          <text class="function-text">{{ item.name }}</text>
        </view>
      </view>
    </view>

    <!-- 课程推荐卡片 -->
    <view class="course-cards">
      <view class="course-card" v-for="(card, index) in courseCards" :key="index" :style="{ backgroundColor: card.bgColor }">
        <view class="card-content">
          <text class="card-title">{{ card.title }}</text>
          <text class="card-subtitle">{{ card.subtitle }}</text>
        </view>
        <image class="card-image" :src="card.image" mode="aspectFit"></image>
      </view>
    </view>

    <!-- 课程列表 -->
    <view class="course-section">
      <view class="section-header">
        <text class="section-title">大家都在学</text>
        <view class="more-btn">
          <text>更多课程</text>
          <uni-icons type="right" size="14" color="#999"></uni-icons>
        </view>
      </view>

      <view class="course-list">
        <view class="course-item" v-for="(course, index) in courseList" :key="index" @click="handleCourseClick(course)">
          <image class="course-cover" :src="course.cover" mode="aspectFill"></image>
          <view class="course-info">
            <text class="course-title">{{ course.title }}</text>
            <view class="course-stats">
              <text class="course-students">{{ course.students }}人学习</text>
              <text class="course-type">{{ course.type }}</text>
            </view>
            <text class="course-desc">{{ course.description }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 轮播图数据
const bannerList = ref([
  {
    title: 'Python编程班',
    subtitle: '产品体验有奖用户调研',
    btnText: '立即参与 >>',
    bgColor: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
    image: '/static/banner/python-banner.png'
  }
])

// 功能模块数据
const functionList = ref([
  { name: '学练课', icon: '/static/icons/study.png', bgColor: '#FF6B6B', badge: '好课' },
  { name: '视频课', icon: '/static/icons/video.png', bgColor: '#9B59B6' },
  { name: '题库', icon: '/static/icons/question.png', bgColor: '#F39C12' },
  { name: '教程', icon: '/static/icons/tutorial.png', bgColor: '#2ECC71' },
  { name: 'VIP会员', icon: '/static/icons/vip.png', bgColor: '#E74C3C', badge: '16周年' },
  { name: '基础入门', icon: '/static/icons/basic.png', bgColor: '#3498DB' },
  { name: '数据分析', icon: '/static/icons/data.png', bgColor: '#1ABC9C' },
  { name: '人工智能', icon: '/static/icons/ai.png', bgColor: '#95A5A6' },
  { name: '爬虫', icon: '/static/icons/spider.png', bgColor: '#34495E' },
  { name: '办公自动化', icon: '/static/icons/office.png', bgColor: '#16A085' }
])

// 课程推荐卡片
const courseCards = ref([
  {
    title: 'Python高薪就业课',
    subtitle: '面向大学、职场就业提效',
    bgColor: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
    image: '/static/cards/job-card.png'
  },
  {
    title: 'Python少儿编程',
    subtitle: '面向小学、初高中学习',
    bgColor: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
    image: '/static/cards/kids-card.png'
  }
])

// 课程列表数据
const courseList = ref([
  {
    cover: '/static/courses/python-basic.png',
    title: 'Python3 入门课程',
    students: '5037',
    type: '学练课',
    description: '爬虫+机器学习? Python无所不能...'
  },
  {
    cover: '/static/courses/python-zero.png',
    title: '零基础入门学Python',
    students: '619',
    type: '视频课',
    description: '通过Python入门到实战全套教程...'
  },
  {
    cover: '/static/courses/python-guide.png',
    title: 'Python3零基础入门先导课',
    students: '5847',
    type: '学练课',
    description: '0基础的python入门先导课程...'
  }
])

// 方法
const handleFunctionClick = (item) => {
  console.log('点击功能:', item.name)
  // 这里可以添加跳转逻辑
}

const handleCourseClick = (course) => {
  console.log('点击课程:', course.title)
  // 这里可以添加跳转到课程详情的逻辑
}

onMounted(() => {
  console.log('发现页面加载完成')
})
</script>

<style lang="scss" scoped>
.discover-container {
  background-color: #f5f5f5;
  min-height: 100vh;
}

// 搜索框样式
.search-section {
  background-color: #fff;
  padding: 20rpx 30rpx;
  
  .search-box {
    display: flex;
    align-items: center;
    background-color: #f8f8f8;
    border-radius: 50rpx;
    padding: 20rpx 30rpx;
    
    .search-input {
      flex: 1;
      margin-left: 20rpx;
      font-size: 28rpx;
      color: #333;
    }
  }
}

// 轮播图样式
.banner-section {
  margin: 20rpx 30rpx;
  
  .banner-swiper {
    height: 300rpx;
    border-radius: 20rpx;
    overflow: hidden;
  }
  
  .banner-item {
    height: 100%;
    border-radius: 20rpx;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  }
  
  .banner-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 40rpx;
  }
  
  .banner-text {
    flex: 1;
    
    .banner-title {
      display: block;
      color: #fff;
      font-size: 32rpx;
      font-weight: bold;
      margin-bottom: 10rpx;
    }
    
    .banner-subtitle {
      display: block;
      color: #fff;
      font-size: 28rpx;
      margin-bottom: 30rpx;
    }
    
    .banner-btn {
      background-color: #FF6B35;
      color: #fff;
      padding: 12rpx 24rpx;
      border-radius: 30rpx;
      font-size: 24rpx;
      display: inline-block;
    }
  }
  
  .banner-image {
    width: 120rpx;
    height: 120rpx;
  }
}

// 功能模块样式
.function-section {
  background-color: #fff;
  margin: 20rpx 30rpx;
  border-radius: 20rpx;
  padding: 40rpx 20rpx;
  
  .function-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: 40rpx;
    
    &:last-child {
      margin-bottom: 0;
    }
  }
  
  .function-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    
    .function-icon {
      width: 80rpx;
      height: 80rpx;
      border-radius: 20rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 15rpx;
    }
    
    .function-text {
      font-size: 24rpx;
      color: #333;
    }
    
    .function-badge {
      position: absolute;
      top: -10rpx;
      right: -10rpx;
      background-color: #FF4757;
      color: #fff;
      font-size: 18rpx;
      padding: 4rpx 8rpx;
      border-radius: 20rpx;
      transform: scale(0.8);
    }
  }
}

// 课程推荐卡片样式
.course-cards {
  margin: 20rpx 30rpx;
  display: flex;
  gap: 20rpx;
  
  .course-card {
    flex: 1;
    height: 200rpx;
    border-radius: 20rpx;
    padding: 30rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    
    .card-content {
      flex: 1;
      
      .card-title {
        display: block;
        color: #fff;
        font-size: 28rpx;
        font-weight: bold;
        margin-bottom: 10rpx;
      }
      
      .card-subtitle {
        display: block;
        color: #fff;
        font-size: 22rpx;
        opacity: 0.9;
      }
    }
    
    .card-image {
      width: 80rpx;
      height: 80rpx;
    }
  }
}

// 课程列表样式
.course-section {
  background-color: #fff;
  margin: 20rpx 30rpx;
  border-radius: 20rpx;
  padding: 30rpx;
  
  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30rpx;
    
    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
    }
    
    .more-btn {
      display: flex;
      align-items: center;
      color: #999;
      font-size: 24rpx;
    }
  }
  
  .course-list {
    .course-item {
      display: flex;
      margin-bottom: 30rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      .course-cover {
        width: 160rpx;
        height: 120rpx;
        border-radius: 12rpx;
        margin-right: 20rpx;
      }
      
      .course-info {
        flex: 1;
        
        .course-title {
          display: block;
          font-size: 28rpx;
          font-weight: bold;
          color: #333;
          margin-bottom: 10rpx;
        }
        
        .course-stats {
          display: flex;
          align-items: center;
          margin-bottom: 10rpx;
          
          .course-students {
            font-size: 22rpx;
            color: #999;
            margin-right: 20rpx;
          }
          
          .course-type {
            font-size: 22rpx;
            color: #999;
          }
        }
        
        .course-desc {
          font-size: 24rpx;
          color: #666;
          line-height: 1.4;
        }
      }
    }
  }
}
</style>