"use client";

import Image from "next/image";
import Link from "next/link";
import { Users, Building2 } from "lucide-react";
import { motion } from "framer-motion";

export interface FeaturedEmployer {
    id: string;
    name: string;
    logo: string | null;
    openPositions: number;
}

interface TopCompaniesProps {
    companies: FeaturedEmployer[];
}

export function TopCompanies({ companies }: TopCompaniesProps) {
    if (!companies || companies.length === 0) return null;

    // Limit to 4 companies
    const displayCompanies = companies.slice(0, 4);

    return (
        <section className="py-24 bg-white relative z-10 border-b border-slate-100">
            <div className="max-w-7xl mx-auto px-6">
                <div className="text-center mb-16">
                    <h2 className="text-3xl md:text-4xl font-extrabold text-deep-navy mb-4 font-display">
                        Top Companies Hiring on Proten Connect
                    </h2>
                    <p className="text-lg text-slate-500 max-w-2xl mx-auto">
                        Partner with industry leaders and explore premium career opportunities tailored for you.
                    </p>
                </div>

                <motion.div 
                    initial="hidden"
                    whileInView="visible"
                    viewport={{ once: true, margin: "-100px" }}
                    variants={{
                        hidden: {},
                        visible: { transition: { staggerChildren: 0.1 } }
                    }}
                    className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-8 mt-12"
                >
                    {displayCompanies.map((company, index) => (
                        <motion.div 
                            key={company.id} 
                            variants={{
                                hidden: { opacity: 0, y: 20 },
                                visible: { opacity: 1, y: 0, transition: { duration: 0.5 } }
                            }}
                            whileHover={{ scale: 1.02, y: -5 }}
                            className="bg-white rounded-[16px] border border-[#e5e7eb] shadow-sm hover:shadow-lg transition-shadow duration-300 p-6 flex flex-col items-center text-center group"
                        >
                            <div className="w-[72px] h-[72px] bg-white rounded-full flex items-center justify-center border border-slate-100 shadow-sm mb-5 relative -mt-12 group-hover:-translate-y-1 transition-transform overflow-hidden">
                                {company.logo ? (
                                    <img
                                        alt={`${company.name} Logo`}
                                        className="w-10 h-10 object-contain"
                                        src={company.logo}
                                    />
                                ) : (
                                    <Building2 className="w-8 h-8 text-slate-400" />
                                )}
                            </div>
                            <h3 className="text-xl font-bold text-deep-navy font-display mb-4 line-clamp-1" title={company.name}>
                                {company.name}
                            </h3>
                            <div className="mb-6">
                                <span className="inline-block px-4 py-1.5 bg-emerald-50 text-emerald-700 text-sm font-bold rounded-full border border-emerald-100">
                                    {company.openPositions} Active {company.openPositions === 1 ? 'Role' : 'Roles'}
                                </span>
                            </div>
                            <Link href={`/jobs?employer=${company.id}`} className="w-full">
                                <button className="w-full py-3 bg-primary text-white text-sm font-bold rounded-xl hover:bg-primary/90 transition-colors mt-auto">
                                    View Openings
                                </button>
                            </Link>
                        </motion.div>
                    ))}
                </motion.div>
            </div>
        </section>
    );
}
