"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 (
{task.progress >= 100 ? (
{daysInfo ? (
{overdue &&
{task.plannedHours > 0 && task.workedHours > 0 ? (
'Progreso vs tiempo invertido'
) : (