import React from 'react'; import { Task } from '../../entities/Task'; import { TFunction } from 'i18next'; import { isTaskInProgress, isTaskPlanned, isTaskWaiting, } from '../../constants/taskStatus'; // Check if task is in today's plan (has active status) const isTaskInTodayPlan = (task: Task): boolean => isTaskInProgress(task.status) || isTaskPlanned(task.status) || isTaskWaiting(task.status); interface DueBuckets { overdue: Task[]; week: Task[]; month: Task[]; unscheduled: Task[]; totalDue: number; } interface TaskStats { total: number; completed: number; inProgress: number; notStarted: number; overdue: number; dueSoon: number; completionRate: number; } interface ProjectInsightsPanelProps { taskStats: TaskStats; completionGradient: string; dueBuckets: DueBuckets; dueHighlights: Task[]; nextBestAction: Task | null; getDueDescriptor: (task: Task) => string; onStartNextAction: () => Promise | void; t: TFunction; completionTrend: { label: string; count: number }[]; upcomingDueTrend: { label: string; count: number }[]; createdTrend: { label: string; count: number }[]; weeklyPace: { lastWeek: number; prevWeek: number; delta: number }; monthlyCompleted: number; upcomingInsights?: { peakLabel: string; peakCount: number; nextThreeDays: number; nextWeek: number; }; } const ProjectInsightsPanel: React.FC = ({ taskStats, completionGradient, nextBestAction, getDueDescriptor, onStartNextAction, t, upcomingDueTrend, weeklyPace, monthlyCompleted, upcomingInsights, }) => { const maxUpcoming = Math.max(...upcomingDueTrend.map((d) => d.count), 1); return (

{t('projects.progress', 'Progress')}

{t('projects.taskMomentum', 'Task momentum')}

{taskStats.total} {t('tasks.tasks', 'tasks')}
{taskStats.completionRate}% {t('common.done', 'done')}
{t('projects.activeTasks', 'Active tasks')} {Math.max( taskStats.total - taskStats.completed, 0 )}
{taskStats.overdue}{' '} {t('tasks.overdue', 'overdue')},{' '} {taskStats.dueSoon}{' '} {t('tasks.dueSoon', 'due soon')}
{t('tasks.progress', 'Progress')} {taskStats.completionRate}%
0 ? taskStats.completionRate : 0}%`, }} >

{t('projects.dueSchedule', 'Due schedule')}

{t('projects.next14Days', 'Next 14 days')}
{upcomingDueTrend.some((d) => d.count > 0) ? ( <>
{upcomingDueTrend.map((d, idx) => { const intensity = maxUpcoming > 0 ? Math.max( (d.count / maxUpcoming) * 0.8, 0.12 ) : 0; return (
{d.label} {d.count}
); })}
{upcomingInsights && (
{t('projects.peakDay', 'Peak')}:{' '} {upcomingInsights.peakCount > 0 ? `${upcomingInsights.peakLabel} · ${upcomingInsights.peakCount}` : t('projects.none', 'None')} {t('projects.next3days', 'Next 3 days')}:{' '} {upcomingInsights.nextThreeDays} {t('projects.nextWeek', 'Next 7 days')}:{' '} {upcomingInsights.nextWeek}
)} ) : (

{t( 'projects.noUpcomingDue', 'No due dates in the next 14 days.' )}

)}

{t('projects.recentCompletion', 'Recent completion')}

{t('projects.last7And30', 'Last 7 & 30 days')}

{t('projects.weeklyPace', 'Weekly pace')}

{weeklyPace.lastWeek}

{t( 'projects.prevWeekCompleted', '{{count}} prior week', { count: weeklyPace.prevWeek, } )}

0 ? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-200' : weeklyPace.delta === 0 ? 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300' : 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-200' }`} > {weeklyPace.delta > 0 ? '+' : ''} {weeklyPace.delta}{' '} {t('projects.vsPrevWeek', 'vs prev week')}

{t( 'projects.monthlyCompletion', '30-day completions' )}

{monthlyCompleted}

{t('projects.last30Days', 'Last 30 days')}

{t('projects.nextUp', 'Next best action')}

{t('projects.focusTask', 'Most impactful task')}

{nextBestAction && ( {getDueDescriptor(nextBestAction)} )}
{nextBestAction ? (

{nextBestAction.name}

{nextBestAction.note && (

{nextBestAction.note}

)}
{nextBestAction.priority && ( {t('tasks.priority', 'Priority')}:{' '} {String(nextBestAction.priority)} )} {isTaskInTodayPlan(nextBestAction) && ( {t('tasks.todayPlan', 'Today plan')} )} {(nextBestAction.status === 'in_progress' || nextBestAction.status === 1) && ( {t('task.status.inProgress', 'In progress')} )}
{t( 'projects.focusHint', 'Shifts this task to in progress and today' )}
) : (

{t( 'projects.noNextAction', 'All clear—no outstanding tasks.' )}

)}
); }; export default ProjectInsightsPanel;