'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Skeleton } from '@/components/ui/skeleton' import { AnimatedCard } from '@/components/shared/animated-container' import { ArrowDown, ChevronDown, ChevronUp, TrendingDown } from 'lucide-react' import { cn, formatCategory } from '@/lib/utils' export function PreviousRoundSection({ currentRoundId }: { currentRoundId: string }) { const [collapsed, setCollapsed] = useState(false) const { data, isLoading } = trpc.analytics.getPreviousRoundComparison.useQuery( { currentRoundId }, { refetchInterval: 60_000 }, ) if (isLoading) { return } if (!data || !data.hasPrevious) { return null } const { previousRound, currentRound, eliminated, categoryBreakdown, countryAttrition } = data return ( {!collapsed && ( {/* Headline Stat */}

{eliminated} project{eliminated !== 1 ? 's' : ''} eliminated

{previousRound.projectCount} → {currentRound.projectCount}

{/* Category Survival Bars */} {categoryBreakdown && categoryBreakdown.length > 0 && (

By Category

{categoryBreakdown.map((cat: any) => { const maxVal = Math.max(cat.previous, 1) const prevPct = 100 const currPct = (cat.current / maxVal) * 100 return (
{formatCategory(cat.category)} {cat.previous} → {cat.current} (-{cat.eliminated})
) })}
)} {/* Country Attrition */} {countryAttrition && countryAttrition.length > 0 && (

Country Attrition (Top 10)

{countryAttrition.map((c: any) => (
{c.country} -{c.lost}
))}
)} {/* Score Comparison */} {previousRound.avgScore != null && currentRound.avgScore != null && (

{previousRound.name}

{typeof previousRound.avgScore === 'number' ? previousRound.avgScore.toFixed(1) : previousRound.avgScore}

Avg Score

{currentRound.name}

{typeof currentRound.avgScore === 'number' ? currentRound.avgScore.toFixed(1) : currentRound.avgScore}

Avg Score

)} )} ) }