"use client";

import Link from "next/link";
import { ArrowRight } from "lucide-react";
import { motion } from "framer-motion";
import { CONTENT_PREVIEW_ITEMS } from "~/lib/data";

const TAG_COLORS: Record<string, string> = {
  城市: "bg-blue-50 text-blue-700",
  专题: "bg-emerald-50 text-emerald-700",
  工具: "bg-amber-50 text-amber-700",
  活动: "bg-rose-50 text-rose-700",
  学习路径: "bg-violet-50 text-violet-700",
  会员: "bg-neutral-100 text-neutral-700",
};

export function ContentPreview() {
  return (
    <section className="bg-white py-16 md:py-24">
      <div className="container mx-auto px-4 md:px-6">
        <motion.h2
          initial={{ opacity: 0, y: 12 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true, margin: "-80px" }}
          className="text-2xl font-semibold text-neutral-900 md:text-3xl"
        >
          本周精选
        </motion.h2>
        <motion.p
          initial={{ opacity: 0 }}
          whileInView={{ opacity: 1 }}
          viewport={{ once: true }}
          className="mt-2 text-neutral-600"
        >
          城市、专题、工具、活动，持续更新
        </motion.p>

        <div className="mt-8 grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
          {CONTENT_PREVIEW_ITEMS.map((item, i) => (
            <motion.div
              key={item.id}
              initial={{ opacity: 0, y: 16 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true, margin: "-40px" }}
              transition={{ delay: Math.min(i * 0.05, 0.2) }}
            >
              <Link
                href={item.href}
                target="_blank"
                rel="noopener noreferrer"
                className="group block rounded-xl border border-neutral-200 p-5 transition-all hover:border-neutral-300 hover:shadow-md"
              >
                <span
                  className={`inline-block rounded-md px-2 py-0.5 text-xs font-medium ${
                    TAG_COLORS[item.type] ?? "bg-neutral-100 text-neutral-600"
                  }`}
                >
                  {item.tag}
                </span>
                <h3 className="mt-3 font-medium text-neutral-900">
                  {item.title}
                </h3>
                <p className="mt-1 text-sm text-neutral-500">{item.summary}</p>
                <span className="mt-3 inline-flex items-center gap-1 text-sm font-medium text-neutral-600 group-hover:text-neutral-900">
                  查看详情
                  <ArrowRight className="h-4 w-4 transition-transform group-hover:translate-x-1" />
                </span>
              </Link>
            </motion.div>
          ))}
        </div>
      </div>
    </section>
  );
}
