"use client"; import Link from "next/link"; import type { Route } from "next"; const PRIORITY_STYLES: Record = { URGENT: { bg: "bg-red-100 dark:bg-red-900/30", text: "text-red-700 dark:text-red-300", label: "Urgent" }, HIGH: { bg: "bg-orange-100 dark:bg-orange-900/30", text: "text-orange-700 dark:text-orange-300", label: "High" }, NORMAL: { bg: "bg-blue-100 dark:bg-blue-900/30", text: "text-blue-700 dark:text-blue-300", label: "Normal" }, LOW: { bg: "bg-gray-100 dark:bg-gray-800", text: "text-gray-500 dark:text-gray-400", label: "Low" }, }; const STATUS_LABELS: Record = { OPEN: "Open", IN_PROGRESS: "In Progress", DONE: "Done", DISMISSED: "Dismissed", }; function isOverdue(dueDate: string | Date | null | undefined): boolean { if (!dueDate) return false; const d = typeof dueDate === "string" ? new Date(dueDate) : dueDate; return d.getTime() < Date.now(); } function formatDate(date: string | Date): string { const d = typeof date === "string" ? new Date(date) : date; return d.toLocaleDateString("en-GB", { day: "2-digit", month: "short", year: "numeric" }); } function isApprovalAction(action: string | null | undefined): boolean { return !!action && action.startsWith("approve_"); } export interface TaskCardProps { task: { id: string; title: string; body?: string | null; priority: string; taskStatus?: string | null; taskAction?: string | null; dueDate?: string | Date | null; entityType?: string | null; link?: string | null; createdAt: string | Date; completedBy?: string | null; }; onStatusChange?: (id: string, status: string) => void; compact?: boolean; } export function TaskCard({ task, onStatusChange, compact }: TaskCardProps) { const priority = PRIORITY_STYLES[task.priority] ?? PRIORITY_STYLES.NORMAL!; const status = task.taskStatus ?? "OPEN"; const overdue = isOverdue(task.dueDate) && status !== "DONE" && status !== "DISMISSED"; const isDone = status === "DONE" || status === "DISMISSED"; const showApprovalButtons = isApprovalAction(task.taskAction) && !isDone; const titleContent = ( {task.title} ); return (
{/* Header row */}
{task.link && !isDone ? ( {titleContent} ) : ( titleContent )} {!compact && task.body && (

{task.body}

)}
{/* Priority badge */} {priority.label}
{/* Meta row */}
{/* Status */} {STATUS_LABELS[status] ?? status} {/* Due date */} {task.dueDate && ( {overdue ? "Overdue: " : "Due: "} {formatDate(task.dueDate)} )} {/* Entity type */} {!compact && task.entityType && ( {task.entityType} )} {/* Completed by */} {isDone && task.completedBy && ( Completed )}
{/* Action buttons */} {!isDone && onStatusChange && (
{showApprovalButtons ? ( <> ) : ( <> {status === "OPEN" && ( )} )}
)}
); }