'use client'; import { useApp } from '@/app/providers'; import { TopBar } from '@/components/TopBar'; import { useProgress } from '@/lib/progress'; export interface SubjectStats { id: string; key: string; lessons: { id: string; number: number; titleKey: string | null; title: string | null; taskCount: number; }[]; } /** * Progress overview: totals at the top, then a bar per subject and a per-lesson * breakdown, following the layout of the desktop statistics page. */ export function StatsScreen({ tracked, locked, }: { tracked: SubjectStats[]; locked: { id: string; key: string }[]; }) { const { t, tOpt } = useApp(); const { doneCount, ready } = useProgress(); const totals = tracked.reduce( (acc, subject) => { const total = subject.lessons.reduce((a, l) => a + l.taskCount, 0); const done = subject.lessons.reduce((a, l) => a + doneCount(subject.id, l.id), 0); const finished = subject.lessons.filter( (l) => l.taskCount > 0 && doneCount(subject.id, l.id) >= l.taskCount ).length; return { done: acc.done + done, total: acc.total + total, finishedUnits: acc.finishedUnits + finished, openUnits: acc.openUnits + subject.lessons.length, }; }, { done: 0, total: 0, finishedUnits: 0, openUnits: 0 } ); const percent = totals.total ? Math.round((totals.done / totals.total) * 100) : 0; return (

{t('stats_title')}

{t('stats_sub')}

{t('stats_section')}

{tracked.map((subject) => { const total = subject.lessons.reduce((a, l) => a + l.taskCount, 0); const done = subject.lessons.reduce((a, l) => a + doneCount(subject.id, l.id), 0); return (
{/* Per-lesson detail, only where a lesson has tasks. */}
{subject.lessons .filter((lesson) => lesson.taskCount > 0) .map((lesson) => { const lessonDone = doneCount(subject.id, lesson.id); return ( ); })}
); })} {locked.map((subject) => ( ))}
); } const Cell = ({ label, value }: { label: string; value: string }) => (
{value}
{label}
); function Row({ name, count, ratio, small, dim, }: { name: string; count: string; ratio: number; small?: boolean; dim?: boolean; }) { const complete = ratio >= 1; return (
{name} {count}
); }