'use client' import Link from 'next/link' import type { Route } from 'next' import { trpc } from '@/lib/trpc/client' import { Card, CardContent } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { CircleDot, AlertTriangle, Upload, UserPlus, Settings, ClipboardCheck, Users, Send, FileDown, Calendar, Eye, Presentation, Vote, Play, Lock, } from 'lucide-react' import { GeographicSummaryCard } from '@/components/charts' import { AnimatedCard } from '@/components/shared/animated-container' import { motion } from 'motion/react' import { CompetitionPipeline } from '@/components/dashboard/competition-pipeline' import { RoundStats } from '@/components/dashboard/round-stats' import { ActiveRoundPanel } from '@/components/dashboard/active-round-panel' import { SmartActions } from '@/components/dashboard/smart-actions' import { ProjectListCompact } from '@/components/dashboard/project-list-compact' import { ActivityFeed } from '@/components/dashboard/activity-feed' import { CategoryBreakdown } from '@/components/dashboard/category-breakdown' import { DashboardSkeleton } from '@/components/dashboard/dashboard-skeleton' import { RecentEvaluations } from '@/components/dashboard/recent-evaluations' type DashboardContentProps = { editionId: string sessionName: string } type QuickAction = { label: string href: string icon: React.ElementType } function getContextualActions( activeRound: { id: string; roundType: string } | null ): QuickAction[] { if (!activeRound) { return [ { label: 'Rounds', href: '/admin/rounds', icon: CircleDot }, { label: 'Import', href: '/admin/projects/new', icon: Upload }, { label: 'Invite', href: '/admin/members', icon: UserPlus }, ] } const roundHref = `/admin/rounds/${activeRound.id}` switch (activeRound.roundType) { case 'INTAKE': return [ { label: 'Import Projects', href: '/admin/projects/new', icon: Upload }, { label: 'Review', href: roundHref, icon: ClipboardCheck }, { label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings }, ] case 'FILTERING': return [ { label: 'Run Screening', href: roundHref, icon: ClipboardCheck }, { label: 'Review Results', href: `${roundHref}?tab=filtering`, icon: Eye }, { label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings }, ] case 'EVALUATION': return [ { label: 'Assignments', href: `${roundHref}?tab=assignments`, icon: Users }, { label: 'Send Reminders', href: `${roundHref}?tab=assignments`, icon: Send }, { label: 'Export', href: roundHref, icon: FileDown }, ] case 'SUBMISSION': return [ { label: 'Submissions', href: roundHref, icon: ClipboardCheck }, { label: 'Deadlines', href: `${roundHref}?tab=config`, icon: Calendar }, { label: 'Status', href: `${roundHref}?tab=projects`, icon: Eye }, ] case 'MENTORING': return [ { label: 'Mentors', href: `${roundHref}?tab=projects`, icon: Users }, { label: 'Progress', href: roundHref, icon: Eye }, { label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings }, ] case 'LIVE_FINAL': return [ { label: 'Live Control', href: roundHref, icon: Presentation }, { label: 'Results', href: `${roundHref}?tab=projects`, icon: Vote }, { label: 'Configure', href: `${roundHref}?tab=config`, icon: Settings }, ] case 'DELIBERATION': return [ { label: 'Sessions', href: roundHref, icon: Play }, { label: 'Results', href: `${roundHref}?tab=projects`, icon: Eye }, { label: 'Lock Results', href: roundHref, icon: Lock }, ] default: return [ { label: 'Rounds', href: '/admin/rounds', icon: CircleDot }, { label: 'Import', href: '/admin/projects/new', icon: Upload }, { label: 'Invite', href: '/admin/members', icon: UserPlus }, ] } } export function DashboardContent({ editionId, sessionName }: DashboardContentProps) { const { data, isLoading, error } = trpc.dashboard.getStats.useQuery( { editionId }, { enabled: !!editionId, retry: 1, refetchInterval: 30_000 } ) const { data: recentEvals } = trpc.dashboard.getRecentEvaluations.useQuery( { editionId, limit: 8 }, { enabled: !!editionId, refetchInterval: 30_000 } ) if (isLoading) { return } if (error) { return (

Failed to load dashboard

{error.message || 'An unexpected error occurred. Please try refreshing the page.'}

) } if (!data) { return (

Edition not found

The selected edition could not be found

) } const { edition, pipelineRounds, activeRoundId, nextActions, projectCount, newProjectsThisWeek, totalJurors, activeJurors, evaluationStats, totalAssignments, latestProjects, recentlyActiveProjects, categoryBreakdown, oceanIssueBreakdown, recentActivity, } = data const activeRound = activeRoundId ? pipelineRounds.find((r) => r.id === activeRoundId) ?? null : null // Find next draft round for summary panel const lastActiveSortOrder = Math.max( ...pipelineRounds.filter((r) => r.status === 'ROUND_ACTIVE').map((r) => r.sortOrder), -1 ) const nextDraftRound = pipelineRounds.find( (r) => r.status === 'ROUND_DRAFT' && r.sortOrder > lastActiveSortOrder ) ?? null const quickActions = getContextualActions(activeRound) return ( <> {/* Page Header */}

{edition.name} {edition.year}

Welcome back, {sessionName}

{quickActions.map((action) => ( ))}
{/* Competition Pipeline */} {/* Round-Specific Stats */} {/* Two-Column Layout */}
{/* Left Column */}
{activeRound && ( )} {recentEvals && recentEvals.length > 0 && ( )}
{/* Right Column */}
{/* Bottom Full Width */}
) }