'use client'; import { useState, useEffect, useRef } from 'react'; import Image from 'next/image'; import { motion, useInView } from 'framer-motion'; import { Card, CardBody, Chip } from '@heroui/react'; import { Calculator, TrendingUp } from 'lucide-react'; import { useLanguage } from '@/contexts/LanguageContext'; import { useTheme } from '@/contexts/ThemeContext'; import { useCountUp } from '@/hooks/useCountUp'; export default function HowItWorksSection() { const { t } = useLanguage(); const { theme } = useTheme(); const [activeStep, setActiveStep] = useState(1); const sectionRef = useRef(null); const isInView = useInView(sectionRef, { once: true, amount: 0.3 }); const investAmount = useCountUp(100000, 1500, 0.85); const earnAmount = useCountUp(5150, 1500, 0.85); // Step 3 inner grid 自适应缩放 const gridRef = useRef(null); const [gridScale, setGridScale] = useState(1); useEffect(() => { const el = gridRef.current; if (!el) return; const observer = new ResizeObserver(([entry]) => { setGridScale(Math.min(1, entry.contentRect.width / 466)); }); observer.observe(el); return () => observer.disconnect(); }, []); const isDark = theme === 'dark'; const steps = [ { number: 1, title: t('how.step1.title'), description: t('how.step1.desc'), hasLine: true }, { number: 2, title: t('how.step2.title'), description: t('how.step2.desc'), hasLine: true }, { number: 3, title: t('how.step3.title'), description: t('how.step3.desc'), hasLine: false } ]; return (
{/* 左侧:标题 + 步骤 */}

{t('how.title')}

{steps.map((step, index) => { const isActive = activeStep === step.number; return ( setActiveStep(step.number)} className="flex flex-row gap-6 items-start justify-start flex-shrink-0 relative cursor-pointer" initial={{ x: '-3rem', opacity: 0 }} animate={isInView ? { x: 0, opacity: 1 } : { x: '-3rem', opacity: 0 }} whileHover={{ opacity: 0.8 }} transition={{ duration: 0.3, ease: 'easeOut', delay: index * 0.15 }} >
{isActive ? (
{step.number}
) : (
{step.number}
)} {step.hasLine && (
)}

{step.title}

{step.description}

); })}
{/* 右侧:卡片区 */} <> {/* Step 1 背景装饰卡片 — 仅桌面端显示 */}
USDC
Token
{/* Step 1 主卡片 */}
{t('how.simulator.title')}
+5.2% APY
{t('how.simulator.invest')} ${investAmount.count.toLocaleString()}
{t('how.simulator.earn')}
+${earnAmount.count.toLocaleString()}
Fund Market Connect Wallet
O
APY 30.2%
APY 15.2%
Defi +5.2% APY
{/* Cards Grid Container — 按比例缩放 */}
{[ { left: '8.58px', top: '0.46px', label: '+10% APY', button: 'Boost' }, { left: '160.18px', top: '11.66px', label: '+10% APY', button: 'Boost' }, { left: '312.18px', top: '19.66px', label: '+10% APY', button: 'Boost' }, { left: '160.18px', top: '11.66px', label: 'Get USDC', button: 'SWAP' }, { left: '312.18px', top: '19.66px', label: '10% APY', button: 'LP' }, ].map((item, i) => (
O
{item.label}
{item.button}
))}
); }