import { Suspense } from 'react' import { prisma } from '@/lib/prisma' export const dynamic = 'force-dynamic' import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Progress } from '@/components/ui/progress' import { Skeleton } from '@/components/ui/skeleton' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { FileSpreadsheet, BarChart3, Users, ClipboardList } from 'lucide-react' import { formatDateOnly } from '@/lib/utils' async function ReportsContent() { // Get rounds with evaluation stats const rounds = await prisma.round.findMany({ include: { program: { select: { name: true, }, }, _count: { select: { roundProjects: true, assignments: true, }, }, assignments: { select: { id: true, evaluation: { select: { id: true, status: true }, }, }, }, }, orderBy: { createdAt: 'desc' }, }) // Calculate completion stats for each round const roundStats = rounds.map((round) => { const totalAssignments = round._count.assignments const completedEvaluations = round.assignments.filter( (a) => a.evaluation?.status === 'SUBMITTED' ).length const completionRate = totalAssignments > 0 ? Math.round((completedEvaluations / totalAssignments) * 100) : 0 return { ...round, totalAssignments, completedEvaluations, completionRate, } }) // Calculate totals const totalProjects = roundStats.reduce((acc, r) => acc + r._count.roundProjects, 0) const totalAssignments = roundStats.reduce( (acc, r) => acc + r.totalAssignments, 0 ) const totalEvaluations = roundStats.reduce( (acc, r) => acc + r.completedEvaluations, 0 ) if (rounds.length === 0) { return (

No data to report

Reports will appear here once rounds are created

) } return (
{/* Quick Stats */}
Total Rounds
{rounds.length}

{rounds.filter((r) => r.status === 'ACTIVE').length} active

Total Projects
{totalProjects}

Across all rounds

Assignments
{totalAssignments}

Total assignments

Evaluations
{totalEvaluations}

Completed

{/* Rounds Table - Desktop */} Round Reports Progress overview for each round Round Program Projects Progress Status {roundStats.map((round) => (

{round.name}

{round.votingEndAt && (

Ends: {formatDateOnly(round.votingEndAt)}

)}
{round.program.name} {round._count.roundProjects}
{round.completedEvaluations}/{round.totalAssignments} {round.completionRate}%
{round.status}
))}
{/* Rounds Cards - Mobile */}

Round Reports

{roundStats.map((round) => (

{round.name}

{round.status}

{round.program.name}

{round.votingEndAt && (

Ends: {formatDateOnly(round.votingEndAt)}

)}
{round._count.roundProjects} projects {round.completedEvaluations}/{round.totalAssignments} evaluations
Progress {round.completionRate}%
))}
) } function ReportsSkeleton() { return (
{[...Array(4)].map((_, i) => ( ))}
{[...Array(3)].map((_, i) => ( ))}
) } export default function ObserverReportsPage() { return (
{/* Header */}

Reports

View evaluation progress and statistics

{/* Content */} }>
) }