<script setup lang="ts">
import {
  Gamepad2, BrainCircuit, BookOpen, Trophy,
  Target, BarChart3,
} from 'lucide-vue-next'
import { useScrollReveal } from '@/composables/useScrollReveal'

const { target, isVisible } = useScrollReveal()

const features = [
  {
    icon: Gamepad2,
    title: '趣味闯关体验',
    desc: '将内容变成闯关冒险，激发用户内在驱动力，互动体验越用越想用。',
    color: 'primary',
  },
  {
    icon: BrainCircuit,
    title: '智能分析引擎',
    desc: '主观内容秒级处理，关键信息高亮解析，效率媲美专业团队。',
    color: 'accent',
  },
  {
    icon: BookOpen,
    title: '沉浸式内容体系',
    desc: '从入门到进阶，科学分级内容路径，培养持续探索的动力。',
    color: 'amber',
  },
  {
    icon: Trophy,
    title: '成就激励系统',
    desc: '积分奖励、排行榜、成就勋章，让每一步进步都被看见和鼓励。',
    color: 'rose',
  },
  {
    icon: Target,
    title: '精准内容推荐',
    desc: '智能分析薄弱环节，定向推送相关内容，告别盲目操作。',
    color: 'cyan',
  },
  {
    icon: BarChart3,
    title: '可视化数据报告',
    desc: '多维度数据看板，团队/分类/个人一目了然，数据驱动精细化运营。',
    color: 'violet',
  },
]

const colorMap: Record<string, { bg: string; iconBg: string; text: string; border: string; gradFrom: string; gradTo: string }> = {
  primary: { bg: 'bg-primary/5', iconBg: 'bg-primary/12', text: 'text-primary', border: 'border-primary/10', gradFrom: '#4F46E5', gradTo: '#818CF8' },
  accent: { bg: 'bg-accent/5', iconBg: 'bg-accent/12', text: 'text-accent', border: 'border-accent/10', gradFrom: '#22C55E', gradTo: '#4ADE80' },
  amber: { bg: 'bg-amber-500/5', iconBg: 'bg-amber-500/12', text: 'text-amber-600', border: 'border-amber-500/10', gradFrom: '#F59E0B', gradTo: '#FBBF24' },
  rose: { bg: 'bg-rose-500/5', iconBg: 'bg-rose-500/12', text: 'text-rose-600', border: 'border-rose-500/10', gradFrom: '#F43F5E', gradTo: '#FB7185' },
  cyan: { bg: 'bg-cyan-500/5', iconBg: 'bg-cyan-500/12', text: 'text-cyan-600', border: 'border-cyan-500/10', gradFrom: '#06B6D4', gradTo: '#22D3EE' },
  violet: { bg: 'bg-violet-500/5', iconBg: 'bg-violet-500/12', text: 'text-violet-600', border: 'border-violet-500/10', gradFrom: '#8B5CF6', gradTo: '#A78BFA' },
}
</script>

<template>
  <section id="features" class="relative py-24 lg:py-32 bg-white overflow-hidden">
    <div class="absolute top-0 left-0 right-0 h-px bg-gradient-to-r from-transparent via-primary/20 to-transparent" />

    <div class="absolute top-32 -right-20 w-64 h-64 rounded-full bg-primary/3 blur-3xl" />
    <div class="absolute bottom-20 -left-20 w-48 h-48 rounded-full bg-accent/3 blur-3xl" />

    <div ref="target" class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
      <div
        class="text-center max-w-3xl mx-auto mb-16 lg:mb-20 transition-all duration-700"
        :class="isVisible ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8'"
      >
        <p class="text-sm font-semibold text-primary tracking-wider uppercase mb-3">核心能力</p>
        <h2 class="text-3xl sm:text-4xl lg:text-5xl font-extrabold text-text-heading leading-tight">
          一个平台，<span class="gradient-text">覆盖全场景</span>
        </h2>
        <p class="text-lg text-text-muted mt-5 leading-relaxed">
          从内容分发到数据分析，从任务管理到智能处理，灵犀学为服务的每个环节注入智慧力量
        </p>
      </div>

      <div class="grid sm:grid-cols-2 lg:grid-cols-3 gap-5 lg:gap-6">
        <div
          v-for="(feat, i) in features"
          :key="feat.title"
          class="group relative p-6 lg:p-8 rounded-2xl border bg-white transition-all duration-500 cursor-pointer hover:-translate-y-1 hover:shadow-xl hover:shadow-gray-200/50 overflow-hidden"
          :class="[
            colorMap[feat.color].border,
            isVisible ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-8',
          ]"
          :style="{ transitionDelay: isVisible ? `${i * 100}ms` : '0ms' }"
        >
          <div class="absolute -bottom-6 -right-6 w-32 h-32 rounded-full opacity-[0.06] group-hover:opacity-[0.12] transition-opacity duration-500">
            <svg viewBox="0 0 100 100" class="w-full h-full">
              <circle cx="50" cy="50" r="50" :fill="colorMap[feat.color].gradFrom" />
            </svg>
          </div>
          <div class="absolute -top-3 -right-3 w-16 h-16 rounded-full opacity-[0.04] group-hover:opacity-[0.08] transition-opacity duration-500">
            <svg viewBox="0 0 100 100" class="w-full h-full">
              <circle cx="50" cy="50" r="50" :fill="colorMap[feat.color].gradTo" />
            </svg>
          </div>

          <div class="relative">
            <div
              class="w-14 h-14 rounded-2xl flex items-center justify-center mb-5 transition-transform duration-300 group-hover:scale-110 shadow-sm"
              :class="colorMap[feat.color].iconBg"
            >
              <component :is="feat.icon" class="w-7 h-7" :class="colorMap[feat.color].text" />
            </div>
            <h3 class="text-lg font-bold text-text-heading mb-2.5">{{ feat.title }}</h3>
            <p class="text-sm text-text-muted leading-relaxed">{{ feat.desc }}</p>

            <div class="mt-5 flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity duration-300">
              <div class="h-0.5 w-8 rounded-full" :class="colorMap[feat.color].iconBg" />
              <span class="text-xs font-medium" :class="colorMap[feat.color].text">了解更多</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>
