'use client';

import { motion } from 'framer-motion';
import { useInView } from 'framer-motion';
import { useRef } from 'react';
import { StaticLink } from '@/components/ui/static-link';
import { Button } from '@/components/ui/button';
import { ArrowRight } from 'lucide-react';
import { InsightCard } from '@/components/ui/insight-card';
import { NEWS } from '@/lib/constants';

export function NewsSection() {
  const ref = useRef(null);
  const isInView = useInView(ref, { once: true, margin: '-100px' });

  return (
    <section id="news" role="region" aria-labelledby="news-heading" className="py-20 md:py-28 bg-[#FAFAFA]" ref={ref}>
      <div className="container-wide">
        <motion.div
          initial={{ opacity: 0, y: 20 }}
          animate={isInView ? { opacity: 1, y: 0 } : {}}
          transition={{ duration: 0.5, ease: [0.16, 1, 0.3, 1] }}
          className="text-center max-w-3xl mx-auto mb-14"
        >
          <h2 id="news-heading" className="text-3xl sm:text-4xl font-semibold text-[#1C1C1C] mb-4">
            最新<span className="text-[#C41E3A] font-calligraphy">动态</span>
          </h2>
          <p className="text-base text-[#595959]">
            洞察行业趋势，分享实践经验
          </p>
        </motion.div>

        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 md:gap-8">
          {NEWS.slice(0, 3).map((item, idx) => (
            <InsightCard
              key={item.id}
              title={item.title}
              excerpt={item.excerpt}
              category={item.category}
              readTime="5 分钟"
              publishedAt={item.date}
              imageUrl={item.image}
              href={`/news/${item.id}`}
              featured={idx === 0}
            />
          ))}
        </div>

        <motion.div
          initial={{ opacity: 0, y: 20 }}
          animate={isInView ? { opacity: 1, y: 0 } : {}}
          transition={{ duration: 0.5, delay: 0.3, ease: [0.16, 1, 0.3, 1] }}
          className="mt-12 text-center"
        >
          <Button variant="outline" size="lg" className="group" asChild>
            <StaticLink href="/news">
              查看全部动态
              <ArrowRight className="ml-2 w-4 h-4 transition-transform group-hover:translate-x-1" />
            </StaticLink>
          </Button>
        </motion.div>
      </div>
    </section>
  );
}
