"use client"; import { Target, Clock, Calendar, TrendingUp, FileText, AlertTriangle, CheckCircle2 } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Task } from "@/types/task"; interface TaskStatsProps { task: Task; } // Formatear fecha completa function formatDate(dateString: string | null): string { if (!dateString) return 'No definida'; return new Date(dateString).toLocaleDateString('es-ES', { day: '2-digit', month: 'long', year: 'numeric', }); } // Obtener clase de color según progreso function getProgressColorClass(value: number): string { if (value >= 100) return '[&>div]:bg-green-500'; if (value >= 75) return '[&>div]:bg-blue-500'; if (value >= 50) return '[&>div]:bg-yellow-500'; if (value >= 25) return '[&>div]:bg-orange-500'; return '[&>div]:bg-gray-400'; } // Calcular si está vencida function isOverdue(task: Task): boolean { const endDate = task.endDate || task.plannedEndDate; if (!endDate) return false; return new Date(endDate) < new Date() && task.status !== '2'; } // Calcular días restantes function getDaysRemaining(task: Task): { days: number; label: string } | null { const endDate = task.endDate || task.plannedEndDate; if (!endDate) return null; const end = new Date(endDate); const today = new Date(); today.setHours(0, 0, 0, 0); end.setHours(0, 0, 0, 0); const diffTime = end.getTime() - today.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays < 0) { return { days: Math.abs(diffDays), label: `${Math.abs(diffDays)} días de retraso` }; } else if (diffDays === 0) { return { days: 0, label: 'Vence hoy' }; } else if (diffDays === 1) { return { days: 1, label: 'Vence mañana' }; } else { return { days: diffDays, label: `${diffDays} días restantes` }; } } export function TaskStats({ task }: TaskStatsProps) { const overdue = isOverdue(task); const daysInfo = getDaysRemaining(task); const efficiency = task.plannedHours > 0 ? Math.round((task.workedHours / task.plannedHours) * 100) : 0; return (
{/* Progreso */} Progreso
{task.progress}%

{task.progress >= 100 ? ( Tarea completada ) : task.progress > 0 ? ( 'En progreso' ) : ( 'Sin iniciar' )}

{/* Tiempo */} Tiempo
{task.workedHours > 0 ? `${task.workedHours}h` : '-'}
{task.plannedHours > 0 && ( 100 ? '[&>div]:bg-red-500' : '[&>div]:bg-blue-500'}`} /> )}

{task.plannedHours > 0 ? ( <> de {task.plannedHours}h planificadas {efficiency > 100 && ( ({efficiency}%) )} ) : ( 'Sin estimación' )}

{/* Fecha límite */} Fecha límite
{formatDate(task.endDate || task.plannedEndDate).split(' de ')[0] || '-'}

{daysInfo ? ( {overdue && } {daysInfo.label} ) : ( 'Sin fecha límite' )}

{/* Eficiencia / Estado */} Rendimiento
{task.plannedHours > 0 && task.workedHours > 0 ? ( `${Math.round((task.progress / efficiency) * 100)}%` ) : task.progress > 0 ? ( 'Activa' ) : ( '-' )}

{task.plannedHours > 0 && task.workedHours > 0 ? ( 'Progreso vs tiempo invertido' ) : ( {task.description ? 'Con descripción' : 'Sin descripción'} )}

); }