"use client";

import Link from "next/link";
import { FeaturedJobCard, FeaturedJobProps } from "./FeaturedJobCard";
import { motion } from "framer-motion";

interface TrendingJobsProps {
    jobs: Omit<FeaturedJobProps, "colorTheme">[];
}

export function TrendingJobs({ jobs }: TrendingJobsProps) {
    if (!jobs || jobs.length === 0) return null;

    const colors = ["blue", "purple", "green"];

    // Limit to 6
    const displayJobs = jobs.slice(0, 6);

    return (
        <section className="py-24 bg-white relative z-10" id="jobs">
            <div className="max-w-7xl mx-auto px-6">
                {/* Section Header — pixel-perfect match to design */}
                <div className="flex flex-col md:flex-row items-start md:items-center justify-between mb-16 gap-6">
                    <div>
                        <div className="flex items-center gap-3 mb-3">
                            <h2 className="text-4xl font-bold text-deep-navy font-display">
                                Featured Jobs
                            </h2>
                            <span className="px-3 py-1 bg-primary text-white text-sm font-bold rounded-full">
                                New
                            </span>
                        </div>
                        <p className="text-slate-500 text-lg">
                            The most sought-after roles currently open for applications.
                        </p>
                    </div>
                    <Link
                        href="/jobs"
                        className="flex items-center gap-1.5 text-primary font-bold hover:gap-3 transition-all group shrink-0"
                    >
                        View all
                        <span className="material-symbols-outlined text-xl group-hover:translate-x-1 transition-transform">
                            arrow_right_alt
                        </span>
                    </Link>
                </div>

                <motion.div
                    initial="hidden"
                    whileInView="visible"
                    viewport={{ once: true, margin: "-100px" }}
                    variants={{
                        hidden: {},
                        visible: { transition: { staggerChildren: 0.1 } }
                    }}
                    className="grid md:grid-cols-2 lg:grid-cols-3 gap-6"
                >
                    {displayJobs.map((job, index) => (
                        <motion.div
                            key={job.id}
                            variants={{
                                hidden: { opacity: 0, y: 20 },
                                visible: { opacity: 1, y: 0, transition: { duration: 0.5 } }
                            }}
                        >
                            <FeaturedJobCard
                                job={{
                                    ...job,
                                    colorTheme: colors[index % colors.length]
                                }}
                            />
                        </motion.div>
                    ))}
                </motion.div>
            </div>
        </section>
    );
}
