"use client";

import { Education } from "@/lib/db";
import { GraduationCap, Calendar } from "lucide-react";

interface EducationListProps {
    education: Education[];
}

export function EducationList({ education }: EducationListProps) {
    if (!education || education.length === 0) {
        return (
            <div className="text-center py-8 text-slate-500">
                No education added yet
            </div>
        );
    }

    const sortedEducation = [...education].sort((a, b) =>
        new Date(b.startDate).getTime() - new Date(a.startDate).getTime()
    );

    return (
        <div className="space-y-4">
            {sortedEducation.map((edu) => (
                <div key={edu.id} className="bg-white rounded-xl border border-slate-100 p-6 shadow-sm hover:shadow-md transition-shadow">
                    <div className="flex items-start gap-4">
                        <div className="flex-shrink-0 w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center">
                            <GraduationCap className="h-6 w-6 text-primary" />
                        </div>
                        <div className="flex-1">
                            <h3 className="text-lg font-bold text-slate-900">{edu.degree}</h3>
                            <p className="text-sm font-medium text-slate-600 mt-1">{edu.institution}</p>
                            <p className="text-sm text-slate-500 mt-1">{edu.field}</p>

                            <div className="flex items-center gap-1 mt-2 text-sm text-slate-500">
                                <Calendar className="h-4 w-4" />
                                <span>
                                    {new Date(edu.startDate).getFullYear()} - {new Date(edu.endDate).getFullYear()}
                                </span>
                            </div>

                            {edu.description && (
                                <p className="text-sm text-slate-600 mt-3 leading-relaxed">
                                    {edu.description}
                                </p>
                            )}
                        </div>
                    </div>
                </div>
            ))}
        </div>
    );
}
