import { Suspense } from 'react' import Link from 'next/link' import type { Route } from 'next' 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 { Button } from '@/components/ui/button' import { Skeleton } from '@/components/ui/skeleton' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { Plus, MoreHorizontal, FolderKanban, Eye, Pencil, Copy, } from 'lucide-react' import { formatDateOnly } from '@/lib/utils' async function ProgramsContent() { const programs = await prisma.program.findMany({ // Note: PROGRAM_ADMIN filtering should be handled via middleware or a separate relation include: { competitions: { include: { rounds: { select: { id: true, status: true }, }, }, }, }, orderBy: { createdAt: 'desc' }, }) // Flatten rounds per program for convenience const programsWithRoundCounts = programs.map((p) => { const allRounds = p.competitions.flatMap((c) => c.rounds) const activeRounds = allRounds.filter((r) => r.status === 'ROUND_ACTIVE') return { ...p, roundCount: allRounds.length, activeRoundCount: activeRounds.length } }) if (programsWithRoundCounts.length === 0) { return (

No programs yet

Create your first program to start managing projects and rounds

) } const statusColors: Record = { ACTIVE: 'default', COMPLETED: 'success', DRAFT: 'secondary', ARCHIVED: 'secondary', } return ( <> {/* Desktop table view */} Program Year Rounds Status Created Actions {programsWithRoundCounts.map((program) => (

{program.name}

{program.description && (

{program.description}

)}
{program.year}

{program.roundCount} total

{program.activeRoundCount > 0 && (

{program.activeRoundCount} active

)}
{program.status} {formatDateOnly(program.createdAt)} View Details Edit Apply Settings
))}
{/* Mobile card view */}
{programsWithRoundCounts.map((program) => (
{program.name} {program.year}
{program.status}
Stages {program.roundCount} ({program.activeRoundCount} active)
Created {formatDateOnly(program.createdAt)}
))}
) } function ProgramsSkeleton() { return (
{[...Array(5)].map((_, i) => (
))}
) } export default function ProgramsPage() { return (
{/* Header */}

Programs

Manage your ocean protection programs

{/* Content */} }>
) }