import { memo } from 'react'; import { AlertCircle, ArrowRight, CheckCircle, ChevronUp, Circle, Clock, Minus, Pause, X, } from 'lucide-react'; import { cn } from '../../../lib/utils'; import { Tooltip } from '../../../shared/view/ui'; import type { TaskMasterTask } from '../types'; type TaskCardProps = { task: TaskMasterTask; onClick?: (() => void) | null; showParent?: boolean; className?: string; }; type TaskStatusStyle = { icon: typeof Circle; statusText: string; iconColor: string; textColor: string; }; function getStatusStyle(status?: string): TaskStatusStyle { if (status === 'done') { return { icon: CheckCircle, statusText: 'Done', iconColor: 'text-green-600 dark:text-green-400', textColor: 'text-green-900 dark:text-green-100', }; } if (status === 'in-progress') { return { icon: Clock, statusText: 'In Progress', iconColor: 'text-blue-600 dark:text-blue-400', textColor: 'text-blue-900 dark:text-blue-100', }; } if (status === 'review') { return { icon: AlertCircle, statusText: 'Review', iconColor: 'text-amber-600 dark:text-amber-400', textColor: 'text-amber-900 dark:text-amber-100', }; } if (status === 'deferred') { return { icon: Pause, statusText: 'Deferred', iconColor: 'text-gray-500 dark:text-gray-400', textColor: 'text-gray-700 dark:text-gray-300', }; } if (status === 'cancelled') { return { icon: X, statusText: 'Cancelled', iconColor: 'text-red-600 dark:text-red-400', textColor: 'text-red-900 dark:text-red-100', }; } return { icon: Circle, statusText: 'Pending', iconColor: 'text-slate-500 dark:text-slate-400', textColor: 'text-slate-900 dark:text-slate-100', }; } function renderPriorityIcon(priority?: string) { if (priority === 'high') { return (
); } if (priority === 'medium') { return (
); } if (priority === 'low') { return (
); } return (
); } function getSubtaskProgress(task: TaskMasterTask): { completed: number; total: number; percentage: number } { const subtasks = task.subtasks ?? []; const total = subtasks.length; const completed = subtasks.filter((subtask) => subtask.status === 'done').length; const percentage = total > 0 ? Math.round((completed / total) * 100) : 0; return { completed, total, percentage }; } function TaskCard({ task, onClick = null, showParent = false, className = '' }: TaskCardProps) { const statusStyle = getStatusStyle(task.status); const progress = getSubtaskProgress(task); return (
{task.id}

{task.title}

{showParent && task.parentId && ( Task {task.parentId} )}
{renderPriorityIcon(task.priority)}
{Array.isArray(task.dependencies) && task.dependencies.length > 0 && ( `Task ${dependency}`).join(', ')}`}>
Depends on: {task.dependencies.join(', ')}
)}
{statusStyle.statusText}
{progress.total > 0 && (
Progress:
{progress.completed}/{progress.total}
)}
); } export default memo(TaskCard);