import { ChartColumnIcon, TrendingDownIcon, TrendingUpIcon, TrophyIcon } from 'lucide-react' import { Badge } from '@/components/ui/Badge' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { computeVoteTrend, formatElectionNumber, formatVoteTrendSeriesCompact, NO_ELECTION_BASELINE_MESSAGE, voteTrendBadgeVariant, voteTrendStatusLabel, } from '@/lib/electionInsights' import { BASELINE_TICKET_2022 } from '@/lib/electionResults' import type { NucleusElectoralBaselineViewModel } from '@/utilities/nucleusViewModels' const ticket = BASELINE_TICKET_2022 const barPercent = (votes: number, scale: number): number => { if (scale <= 0 || votes <= 0) return 0 return Math.min(100, Math.round((votes / scale) * 100)) } export const NucleusElectoralBaseline = ({ baseline, }: { baseline: NucleusElectoralBaselineViewModel | null }) => { if (!baseline) { return ( Deputado Federal · Bahia

{NO_ELECTION_BASELINE_MESSAGE}

) } const scale = Math.max( baseline.electorate.validos, baseline.candidate.votes, baseline.winnerFederal?.votes ?? 0, 1, ) const candidateBar = barPercent(baseline.candidate.votes, scale) const trend = computeVoteTrend(baseline.series) return (
{trend.status !== 'noBaseline' ? ( {trend.status === 'increase' ? ( ) : null} Deputado Federal · Bahia

{ticket.candidate.name}

{ticket.candidate.party} · {ticket.candidate.officeLabel}

{formatElectionNumber(baseline.candidate.votes)}

votos · 2022

Série histórica

{formatVoteTrendSeriesCompact(baseline.series)}

{trend.status !== 'noBaseline' ? (

{trend.message}

) : null}
{baseline.president ? (

{ticket.president.name}

{ticket.president.party} · Presidente ( {baseline.president.turn === 2 ? '2º turno' : '1º turno'})

{formatElectionNumber(baseline.president.votes)}

) : null} {baseline.governor ? (

{ticket.governor.name}

{ticket.governor.party} · Governador ( {baseline.governor.turn === 2 ? '2º turno' : '1º turno'})

{formatElectionNumber(baseline.governor.votes)}

) : null}

Eleitorado 2022

Votos válidos {formatElectionNumber(baseline.electorate.validos)}
Brancos {formatElectionNumber(baseline.electorate.brancos)}
Nulos {formatElectionNumber(baseline.electorate.nulos)}
Abstenções {formatElectionNumber(baseline.electorate.abstencoes)}
{baseline.winnerFederal ? (

{formatElectionNumber(baseline.winnerFederal.votes)}

) : null}
) }