<template>
  <div class="activity-section">
    <div class="section-header">
      <span class="section-title">最新活动</span>
      <a href="/mobile/activity/list" class="view-all">
        <span>查看全部</span>
        <span class="chevron">›</span>
      </a>
    </div>

    <div class="activity-scroll">
      <div class="activity-container">
        <div
          class="activity-card"
          v-for="(item, index) in activityList"
          :key="index"
          @click="goToActivity(item)"
          :style="{ marginRight: index === activityList.length - 1 ? '40rpx' : '20rpx' }"
        >
          <img :src="item.image" class="activity-image" alt="activity" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { useRouter } from 'vue-router'
  import { ref } from 'vue'
  import activity1 from '~/assets/images/activity1.png'
  import activity2 from '~/assets/images/activity2.png'
  import activity3 from '~/assets/images/activity2.png'

  const router = useRouter()
  const activityList = ref([
    { id: 1, title: '积分兑换有好礼', image: activity1, url: '/mobile/activity/detail?id=1' },
    { id: 2, title: 'CAD高效学习', image: activity2, url: '/mobile/activity/detail?id=2' },
    { id: 3, title: '学习有奖', image: activity3, url: '/mobile/activity/detail?id=3' },
  ])

  function goToActivity(item: { url: string }) {
    router.push(item.url)
  }
</script>

<style lang="scss" scoped>
  .activity-section {
    margin: 21.53rpx 0;
    //   padding: 0 20rpx;
  }

  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20rpx;
  }

  .section-title {
    font-size: 31rpx;
    font-weight: 500;
    color: #333;
  }

  .view-all {
    display: flex;
    align-items: center;
    font-size: 24rpx;
    color: #666;
    text-decoration: none;
  }
  .view-all .chevron {
    margin-left: 4rpx;
    font-size: 20rpx;
  }

  .activity-scroll {
    width: 100%;
    overflow-x: auto;
    padding-left: 20rpx; // 左侧padding，与section对齐
    margin-left: -20rpx; // 抵消父容器的padding
  }

  .activity-container {
    display: inline-flex;
    padding: 10rpx 0; // 留出阴影空间
  }

  .activity-card {
    width: 330rpx;
    height: 160rpx;
    border-radius: 12rpx;
    overflow: hidden;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
    transition: all 0.2s;

    &:active {
      transform: scale(0.98);
      opacity: 0.9;
    }
  }

  .activity-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
</style>
