"use client"; import { calculateDurationInDays } from "@/app/utils/function/projectDuration"; import { Card, CardHeader, CardTitle, CardContent, CardDescription, } from "ikoncomponents"; import { Badge } from "ikoncomponents"; import { Button } from "ikoncomponents"; import { CalendarDays, Clock, Building2, UserRound, ArrowRight, Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; export type ProjectCardProps = { projectIdentifier: string; projectName: string; projectDescription: string; projectStatus: string; projectClient:string; productType: string; contractedStartDate: string ; contractedEndDate: string ; projectManager:string; }; // A small palette of accent themes. Only the icons, left border and the solid // button are colored — the panels stay neutral so text is always readable. // Each entry carries explicit light + dark classes and uses 600-weight fills // with white text so contrast holds in both themes. Classes are static strings // (not interpolated) so Tailwind keeps them in the build. const ACCENTS = [ { border: "border-l-blue-500", icon: "text-blue-600 dark:text-blue-400", button: "bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-600 dark:hover:bg-blue-500", }, { border: "border-l-emerald-500", icon: "text-emerald-600 dark:text-emerald-400", button: "bg-emerald-600 text-white hover:bg-emerald-700 dark:bg-emerald-600 dark:hover:bg-emerald-500", }, { border: "border-l-violet-500", icon: "text-violet-600 dark:text-violet-400", button: "bg-violet-600 text-white hover:bg-violet-700 dark:bg-violet-600 dark:hover:bg-violet-500", }, { border: "border-l-amber-500", icon: "text-amber-600 dark:text-amber-400", button: "bg-amber-600 text-white hover:bg-amber-700 dark:bg-amber-600 dark:hover:bg-amber-500", }, { border: "border-l-rose-500", icon: "text-rose-600 dark:text-rose-400", button: "bg-rose-600 text-white hover:bg-rose-700 dark:bg-rose-600 dark:hover:bg-rose-500", }, { border: "border-l-cyan-500", icon: "text-cyan-600 dark:text-cyan-400", button: "bg-cyan-600 text-white hover:bg-cyan-700 dark:bg-cyan-600 dark:hover:bg-cyan-500", }, ] as const; export default function ProjectCard({ projectIdentifier, projectName, projectDescription, projectStatus, projectClient, productType, projectManager, contractedStartDate, contractedEndDate, }: ProjectCardProps) { const router = useRouter(); // Shows a spinner on the button from the moment it's clicked until this card // unmounts (i.e. the project details route has taken over). The details page // then renders its own spinner while it finishes loading. const [isNavigating, setIsNavigating] = useState(false); const duration = calculateDurationInDays(contractedStartDate,contractedEndDate); const handleViewDetails = () => { setIsNavigating(true); router.push(`/main/planning/projects/${projectIdentifier}`); }; // Pick a stable accent per project so the same card is always the same color. const accent = (() => { const key = projectIdentifier || projectName || ""; let hash = 0; for (let i = 0; i < key.length; i++) { hash = (hash * 31 + key.charCodeAt(i)) >>> 0; } return ACCENTS[hash % ACCENTS.length]; })(); // Map a project status to a badge style so the state reads at a glance. const statusVariant = (() => { switch (projectStatus?.toLowerCase()) { case "completed": return "verified" as const; case "active": case "ongoing": return "default" as const; default: return "secondary" as const; } })(); return (
{projectName}
{projectStatus || "Unknown"}
{/* Description */} {projectDescription || "No description provided."} {/* Meta — neutral panel, colored icons, full-width rows so values stay readable */}
{contractedStartDate || "to"} – {contractedEndDate || "—"}
{duration}d
{projectClient || "—"}
{projectManager || "—"}
); }