import { User } from "@/lib/db";
import { Badge } from "lucide-react";
import Link from "next/link";

interface CandidateCardProps {
    candidate: User;
    matchScore?: number;
}

export function CandidateCard({ candidate, matchScore }: CandidateCardProps) {
    return (
        <div className="group relative flex flex-col rounded-2xl border border-slate-100 bg-white p-6 shadow-sm transition-all hover:border-primary/50 hover:shadow-md">
            <div className="flex items-start justify-between">
                <div className="flex items-center gap-4">
                    <div className="flex h-12 w-12 items-center justify-center rounded-full bg-slate-100 text-lg font-bold text-slate-500">
                        {candidate.name.split(" ").map((n: string) => n[0]).join("")}
                    </div>
                    <div>
                        <h3 className="font-bold text-slate-900 group-hover:text-primary transition-colors">
                            {candidate.name}
                        </h3>
                        <p className="text-sm text-slate-500">{candidate.title || "Candidate"}</p>
                    </div>
                </div>
                {matchScore !== undefined && matchScore > 0 && (
                    <span className="rounded-full bg-emerald-50 px-2.5 py-1 text-xs font-bold text-emerald-600">
                        {matchScore}% Match
                    </span>
                )}
            </div>

            <div className="mt-4 flex flex-wrap gap-2">
                {(candidate.skills || []).slice(0, 3).map((skill: string, i: number) => (
                    <span
                        key={i}
                        className="rounded-md bg-slate-50 px-2 py-1 text-xs font-medium text-slate-600 border border-slate-100"
                    >
                        {skill}
                    </span>
                ))}
                {(candidate.skills || []).length > 3 && (
                    <span className="rounded-md bg-slate-50 px-2 py-1 text-xs font-medium text-slate-500">
                        +{(candidate.skills || []).length - 3}
                    </span>
                )}
            </div>

            <div className="mt-6 flex items-center justify-between border-t border-slate-50 pt-4">
                <div className="text-xs font-medium text-slate-500">
                    Exp: {candidate.description?.includes("years") ? "5+ Years" : "N/A"}
                </div>
                <Link
                    href={`/messages/${candidate.id}`}
                    className="text-sm font-bold text-primary hover:underline"
                >
                    View Profile
                </Link>
            </div>
        </div>
    );
}

export function CandidateRow({ candidate, matchScore }: CandidateCardProps) {
    return (
        <div className="group flex items-center justify-between rounded-xl border border-slate-100 bg-white p-4 shadow-sm transition-all hover:border-primary/50 hover:shadow-md">
            <div className="flex items-center gap-4">
                <div className="flex h-10 w-10 items-center justify-center rounded-full bg-slate-100 text-sm font-bold text-slate-500">
                    {candidate.name.split(" ").map((n: string) => n[0]).join("")}
                </div>
                <div>
                    <h3 className="text-sm font-bold text-slate-900 group-hover:text-primary transition-colors">
                        {candidate.name}
                    </h3>
                    <p className="text-xs text-slate-500">{candidate.title || "Candidate"}</p>
                </div>
            </div>

            <div className="hidden md:flex flex-wrap gap-2">
                {(candidate.skills || []).slice(0, 2).map((skill: string, i: number) => (
                    <span
                        key={i}
                        className="rounded-md bg-slate-50 px-2 py-0.5 text-xs font-medium text-slate-600 border border-slate-100"
                    >
                        {skill}
                    </span>
                ))}
            </div>

            <div className="flex items-center gap-6">
                {matchScore !== undefined && matchScore > 0 && (
                    <span className="hidden sm:inline-block rounded-full bg-emerald-50 px-2.5 py-1 text-xs font-bold text-emerald-600">
                        {matchScore}%
                    </span>
                )}
                <Link
                    href={`/messages/${candidate.id}`}
                    className="rounded-lg bg-slate-900 px-3 py-1.5 text-xs font-bold text-white hover:bg-primary transition-colors"
                >
                    View
                </Link>
            </div>
        </div>
    );
}
