import type {Metadata} from 'next'; import {notFound} from 'next/navigation'; import {getTranslations, setRequestLocale} from 'next-intl/server'; import {PositionChip, ResultBadge} from '@/components/badges'; import {ProportionBar} from '@/components/charts'; import {ExternalLink} from '@/components/ExternalLink'; import {Icon} from '@/components/Icon'; import {Notice} from '@/components/Notice'; import {Breadcrumbs, SectionHead} from '@/components/PageHeader'; import {Link} from '@/i18n/navigation'; import {api, NotFoundError, type VoteDetail} from '@/lib/api'; import {formatDate, partyStyle} from '@/lib/format'; const POSITIONS = ['for', 'against', 'abstain', 'absent']; type Props = {params: Promise<{locale: string; id: string}>}; async function loadVote(id: string): Promise { try { return await api.vote(id); } catch (error) { if (error instanceof NotFoundError) notFound(); throw error; } } export async function generateMetadata({params}: Props): Promise { const {id} = await params; const vote = await loadVote(id); return {title: vote.item_title}; } export default async function VotePage({params}: Props) { const {locale, id} = await params; setRequestLocale(locale); const t = await getTranslations('Votes'); const vote = await loadVote(id); const groups = new Map(); for (const v of vote.individual) { const key = v.faction ?? '–'; groups.set(key, [...(groups.get(key) ?? []), v]); } const colors = new Map(vote.positions.map((p) => [p.party, p.color])); const count = (list: VoteDetail['individual'], position: string) => list.filter((v) => v.position === position).length; const dissenters = vote.individual.filter((v) => v.dissent).length; return (

{vote.chamber}{vote.voted_on && <> · {formatDate(vote.voted_on, locale)}} {vote.roll_call && <> · {t('rollCall')}}

{vote.item_title}

{vote.item_ref && {vote.item_ref}} {vote.stage && <> · {vote.stage}}

{vote.url && {t('item')}} {vote.protocol_url && {t('protocol')}}
{vote.positions.length > 0 && (
    {vote.positions.map((p) => (
  • ))}
{!vote.roll_call &&

{t('factionOnly')}

}
)} {vote.positions.length === 0 && !vote.roll_call && {t('splitVote')}} {vote.individual.length > 0 && (
({ key: position, label: t(position as 'for'), value: count(vote.individual, position), className: `seg-${position}` }))} /> {dissenters > 0 && {t('dissentSummary', {count: dissenters})}}
    {[...groups.entries()].map(([faction, members]) => (
  • {POSITIONS.map((p) => count(members, p)).filter(Boolean).join(' / ')}

      {members.map((m) => (
    • {m.full_name} {m.dissent && {t('dissent')}}
    • ))}
  • ))}
)} {vote.raw_text && (
{t('protocolText')}
{vote.raw_text}
)}
); }