<template>
  <section class="section-stats relative overflow-hidden py-20 lg:py-28" ref="sectionRef">
    <!-- 深色渐变背景 -->
    <div class="absolute inset-0" style="background: linear-gradient(135deg, #0f0c29 0%, #1a1040 40%, #0d1b3e 70%, #0a0a1a 100%);"></div>
    <!-- 网格纹理 -->
    <div class="absolute inset-0 pointer-events-none" style="background-image: linear-gradient(rgba(139,92,246,0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(139,92,246,0.04) 1px, transparent 1px); background-size: 48px 48px;"></div>
    <!-- 动态光晕 -->
    <div class="absolute inset-0 pointer-events-none overflow-hidden">
      <div class="stats-orb stats-orb-1"></div>
      <div class="stats-orb stats-orb-2"></div>
      <div class="stats-orb stats-orb-3"></div>
    </div>
    <!-- 顶部彩虹线 -->
    <div class="absolute top-0 left-0 right-0 h-px" style="background: linear-gradient(90deg, transparent 0%, #8b5cf6 20%, #3b82f6 50%, #06b6d4 80%, transparent 100%);"></div>

    <div class="relative z-10 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
      <!-- 标题 -->
      <div class="text-center mb-12 lg:mb-20 reveal-up" :class="{ 'is-visible': isVisible }">
        <span class="inline-flex items-center gap-2 border text-xs font-bold px-4 py-1.5 rounded-full mb-5 tracking-widest uppercase"
          style="background: rgba(139,92,246,0.15); border-color: rgba(139,92,246,0.4); color: #a78bfa;">
          <span class="w-1.5 h-1.5 rounded-full animate-pulse" style="background: #a78bfa;"></span>
          实时数据
        </span>
        <h2 class="stats-heading text-white mb-4 leading-tight">
          数据流转，<span class="stats-gradient-text">毫秒可见</span>
        </h2>
        <p class="text-base lg:text-lg max-w-2xl mx-auto" style="color: rgba(255,255,255,0.5);">每一次工作流执行，都在为你创造价值</p>
      </div>

      <!-- 四大数据卡片 -->
      <div class="grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4 lg:gap-5 mb-6 lg:mb-10">
        <div
          v-for="(stat, idx) in stats"
          :key="stat.label"
          class="stat-card reveal-up"
          :class="{ 'is-visible': isVisible }"
          :style="{ transitionDelay: `${0.1 + idx * 0.1}s` }"
          @mouseenter="hoveredStat = idx"
          @mouseleave="hoveredStat = null"
        >
          <div class="stat-card-top-line" :style="{ background: stat.lineGradient }"></div>
          <div class="stat-card-glow" :style="{ background: stat.glowColor, opacity: hoveredStat === idx ? 1 : 0 }"></div>
          <div class="stat-growth-badge">{{ stat.growth }}</div>
          <div class="stat-icon" :class="{ 'stat-icon-hover': hoveredStat === idx }">{{ stat.icon }}</div>
          <div class="stat-number" :style="{ color: stat.numColor }">{{ isVisible ? stat.displayNum : '0' }}</div>
          <div class="stat-label">{{ stat.label }}</div>
          <div class="stat-sub hidden sm:block">{{ stat.sub }}</div>
          <div class="stat-progress-track">
            <div class="stat-progress-fill"
              :style="{ width: isVisible ? stat.progress : '0%', background: stat.lineGradient, transitionDelay: `${0.5 + idx * 0.1}s` }">
            </div>
          </div>
        </div>
      </div>

      <!-- 底部：系统状态 + 执行路径 -->
      <div class="grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-5 reveal-up" :class="{ 'is-visible': isVisible }" style="transition-delay: 0.5s;">
        <!-- 系统状态面板 -->
        <div class="glass-panel">
          <div class="flex items-center justify-between mb-5">
            <h3 class="font-bold text-white text-sm sm:text-base">系统运行状态</h3>
            <span class="flex items-center gap-1.5 text-xs font-medium px-3 py-1 rounded-full"
              style="background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3);">
              <span class="w-1.5 h-1.5 bg-emerald-400 rounded-full animate-pulse"></span>
              正常
            </span>
          </div>
          <div class="space-y-4">
            <div v-for="metric in systemMetrics" :key="metric.label">
              <div class="flex items-center gap-2 mb-1.5">
                <span class="text-sm">{{ metric.icon }}</span>
                <span class="text-xs sm:text-sm flex-1" style="color: rgba(255,255,255,0.6);">{{ metric.label }}</span>
                <span class="text-xs sm:text-sm font-bold" :style="{ color: metric.numColor }">{{ metric.value }}</span>
              </div>
              <div class="h-1.5 rounded-full overflow-hidden" style="background: rgba(255,255,255,0.08);">
                <div class="h-full rounded-full transition-all duration-1500 ease-out"
                  :style="{ width: isVisible ? metric.width : '0%', background: metric.barGradient }"></div>
              </div>
            </div>
          </div>
        </div>

        <!-- 工作流执行路径 -->
        <div class="glass-panel">
          <div class="flex items-center justify-between mb-5">
            <h3 class="font-bold text-white text-sm sm:text-base">典型工作流执行路径</h3>
            <span class="text-xs font-medium px-3 py-1 rounded-full"
              style="background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3);">实时运行中</span>
          </div>
          <div class="flow-steps-row">
            <div v-for="(step, idx) in flowSteps" :key="step.label" class="flex items-center gap-1 sm:gap-2">
              <div class="flex flex-col items-center">
                <div class="flow-step-node hover:scale-110 transition-transform duration-300"
                  :style="{ background: step.bg, borderColor: step.border }">
                  {{ step.icon }}
                </div>
                <span class="text-xs mt-1 font-medium text-center" style="color: rgba(255,255,255,0.5);">{{ step.label }}</span>
                <span class="text-xs font-bold" :style="{ color: step.timeColor }">{{ step.time }}</span>
              </div>
              <svg v-if="idx < flowSteps.length - 1" class="flow-arrow flex-shrink-0 mb-5" fill="none" stroke="rgba(255,255,255,0.2)" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
              </svg>
            </div>
          </div>
          <div class="mt-4 flex items-center justify-between p-3 rounded-2xl"
            style="background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.2);">
            <span class="text-xs sm:text-sm" style="color: rgba(255,255,255,0.6);">总执行耗时</span>
            <span class="text-xs sm:text-sm font-black text-emerald-400">1.25s ✓ 完成</span>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

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

const isVisible = ref(false)
const sectionRef = ref(null)
const hoveredStat = ref(null)

onMounted(() => {
  const observer = new IntersectionObserver(
    (entries) => { entries.forEach(e => { if (e.isIntersecting) { isVisible.value = true; observer.unobserve(e.target) } }) },
    { threshold: 0.1 }
  )
  if (sectionRef.value) observer.observe(sectionRef.value)
})

const stats = [
  { icon: '🌍', label: '全球用户', sub: '来自 120+ 国家和地区', displayNum: '50,000+', growth: '↑ 23%', numColor: '#c084fc', lineGradient: 'linear-gradient(90deg, #8b5cf6, #a78bfa)', glowColor: 'radial-gradient(circle at 50% 0%, rgba(139,92,246,0.3) 0%, transparent 70%)', progress: '75%' },
  { icon: '⚡', label: '工作流执行', sub: '累计自动化执行次数', displayNum: '1,200万+', growth: '↑ 41%', numColor: '#60a5fa', lineGradient: 'linear-gradient(90deg, #3b82f6, #60a5fa)', glowColor: 'radial-gradient(circle at 50% 0%, rgba(59,130,246,0.3) 0%, transparent 70%)', progress: '88%' },
  { icon: '⏱️', label: '节省工时', sub: '用户累计节省的人工时间', displayNum: '320万小时', growth: '↑ 58%', numColor: '#22d3ee', lineGradient: 'linear-gradient(90deg, #06b6d4, #22d3ee)', glowColor: 'radial-gradient(circle at 50% 0%, rgba(6,182,212,0.3) 0%, transparent 70%)', progress: '92%' },
  { icon: '📦', label: '工作流模板', sub: '社区贡献的精选模板', displayNum: '8,000+', growth: '↑ 35%', numColor: '#34d399', lineGradient: 'linear-gradient(90deg, #10b981, #34d399)', glowColor: 'radial-gradient(circle at 50% 0%, rgba(16,185,129,0.3) 0%, transparent 70%)', progress: '65%' }
]

const systemMetrics = [
  { icon: '✅', label: '在线率', value: '99.9%', width: '99%', barGradient: 'linear-gradient(90deg, #10b981, #34d399)', numColor: '#34d399' },
  { icon: '📈', label: '流量峰值', value: '60%', width: '60%', barGradient: 'linear-gradient(90deg, #3b82f6, #60a5fa)', numColor: '#60a5fa' },
  { icon: '⚡', label: '平均响应时间', value: '180ms', width: '82%', barGradient: 'linear-gradient(90deg, #8b5cf6, #a78bfa)', numColor: '#a78bfa' },
  { icon: '🔄', label: '今日执行次数', value: '15,750次', width: '78%', barGradient: 'linear-gradient(90deg, #f59e0b, #fbbf24)', numColor: '#fbbf24' }
]

const flowSteps = [
  { icon: '📥', label: '数据输入', time: '0.1s', bg: 'rgba(139,92,246,0.15)', border: 'rgba(139,92,246,0.4)', timeColor: '#a78bfa' },
  { icon: '🔀', label: '条件判断', time: '0.2s', bg: 'rgba(59,130,246,0.15)', border: 'rgba(59,130,246,0.4)', timeColor: '#60a5fa' },
  { icon: '🤖', label: 'AI 处理', time: '0.8s', bg: 'rgba(99,102,241,0.15)', border: 'rgba(99,102,241,0.4)', timeColor: '#818cf8' },
  { icon: '📊', label: '数据分析', time: '0.1s', bg: 'rgba(6,182,212,0.15)', border: 'rgba(6,182,212,0.4)', timeColor: '#22d3ee' },
  { icon: '📤', label: '多端输出', time: '0.05s', bg: 'rgba(16,185,129,0.15)', border: 'rgba(16,185,129,0.4)', timeColor: '#34d399' }
]
</script>

<style scoped>
.stats-orb { position: absolute; border-radius: 50%; filter: blur(80px); pointer-events: none; }
.stats-orb-1 { width: 500px; height: 500px; top: -100px; left: -100px; background: radial-gradient(circle, rgba(139,92,246,0.2) 0%, transparent 70%); animation: orbFloat 12s ease-in-out infinite; }
.stats-orb-2 { width: 400px; height: 400px; top: 50%; right: -80px; background: radial-gradient(circle, rgba(59,130,246,0.18) 0%, transparent 70%); animation: orbFloat 15s ease-in-out infinite reverse; }
.stats-orb-3 { width: 350px; height: 350px; bottom: -80px; left: 40%; background: radial-gradient(circle, rgba(6,182,212,0.15) 0%, transparent 70%); animation: orbFloat 10s ease-in-out infinite; }
@keyframes orbFloat { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(20px, -30px); } }

/* 响应式标题 */
.stats-heading {
  font-size: clamp(2rem, 5vw, 3.75rem);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.stats-gradient-text {
  background: linear-gradient(135deg, #a78bfa 0%, #60a5fa 50%, #22d3ee 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* 数据卡片 */
.stat-card {
  position: relative;
  padding: 16px 14px 14px;
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.4s ease;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
}
.stat-card:hover { transform: translateY(-8px) scale(1.02); box-shadow: 0 20px 60px rgba(0,0,0,0.4); border-color: rgba(255,255,255,0.15); }
.stat-card-top-line { position: absolute; top: 0; left: 0; right: 0; height: 2px; border-radius: 18px 18px 0 0; }
.stat-card-glow { position: absolute; top: 0; left: 0; right: 0; height: 100px; pointer-events: none; transition: opacity 0.4s ease; }
.stat-growth-badge { position: absolute; top: 12px; right: 12px; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.stat-icon { font-size: clamp(20px, 3vw, 28px); margin-bottom: 10px; display: inline-block; transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.stat-icon-hover { transform: scale(1.2) rotate(-5deg); }
.stat-number { font-size: clamp(18px, 3vw, 28px); font-weight: 900; margin-bottom: 3px; line-height: 1.1; }
.stat-label { color: rgba(255,255,255,0.85); font-weight: 700; font-size: clamp(11px, 1.5vw, 13px); margin-bottom: 2px; }
.stat-sub { color: rgba(255,255,255,0.35); font-size: 11px; margin-bottom: 12px; }
.stat-progress-track { height: 3px; background: rgba(255,255,255,0.08); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.stat-progress-fill { height: 100%; border-radius: 99px; transition: width 1.5s cubic-bezier(0.4, 0, 0.2, 1); }

/* 玻璃面板 */
.glass-panel { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); backdrop-filter: blur(16px); border-radius: 20px; padding: 20px; }

/* 流程步骤行 */
.flow-steps-row { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 4px; }
.flow-step-node { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 16px; border: 1px solid; }
.flow-arrow { width: 14px; height: 14px; margin-bottom: 20px; }

/* 滚动动画 */
.reveal-up { opacity: 0; transform: translateY(40px); transition: opacity 0.8s ease, transform 0.8s ease; }
.reveal-up.is-visible { opacity: 1; transform: translateY(0); }
.duration-1500 { transition-duration: 1500ms; }

/* ---- 响应式 ---- */
@media (max-width: 640px) {
  .stat-card { padding: 14px 12px 12px; }
  .flow-step-node { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }
  .flow-arrow { width: 10px; height: 10px; }
  .glass-panel { padding: 16px; }
}
@media (max-width: 480px) {
  .stat-number { font-size: 16px; }
  .stat-growth-badge { font-size: 9px; padding: 1px 6px; }
  .flow-steps-row { gap: 2px; }
  .flow-step-node { width: 30px; height: 30px; font-size: 12px; border-radius: 8px; }
  .flow-arrow { width: 8px; height: 8px; }
}
</style>
