import Link from 'next/link' import { ActionPlanStatusBadge } from '@/components/campaign/ActionPlanStatusBadge' import { MunicipalityBaselineCard } from '@/components/campaign/MunicipalityBaselineCard' import { MunicipalityStrategyCard } from '@/components/campaign/MunicipalityStrategyCard' import { MunicipalityUpdateFeed } from '@/components/campaign/MunicipalityUpdateFeed' import { SupportStatusBadge } from '@/components/campaign/SupportStatusBadge' import { Badge } from '@/components/ui/Badge' import type { MunicipalityAgeBandKey } from '@/lib/bahiaMunicipalityDemographics' import { formatElectionNumber } from '@/lib/electionInsights' import { actionPlanKindLabels } from '@/lib/schemas/actionPlan' import type { ActionPlanListViewModel } from '@/utilities/actionPlanViewModels' import { formatBahiaDateTimeLabel } from '@/utilities/campaignTime' import { formatGoalCoverageDeficitLabel, formatGoalCoverageRatioLabel, formatRatioAsPercentLabel, } from '@/utilities/goalCoverage' import type { MunicipalityDossierData } from '@/utilities/municipalityDossierData' import { formatMunicipalityGeographyLabel, municipalityKindLabels, municipalityPriorityLabels, politicalTrendBadgeVariant, politicalTrendLabels, } from '@/utilities/municipalityLabels' import type { MunicipalityAdvisorSummary, MunicipalityDetailViewModel, } from '@/utilities/municipalityViewModels' const dateFormatter = new Intl.DateTimeFormat('pt-BR') const AGE_BAND_LABELS: Record = { '0-17': '0–17 anos', '18-29': '18–29 anos', '30-59': '30–59 anos', '60+': '60+ anos', } const SectionHeader = ({ id, title, seeAllHref, seeAllLabel, }: { id: string title: string seeAllHref?: string seeAllLabel?: string }) => (

{title}

{seeAllHref ? ( {seeAllLabel ?? 'Ver tudo'} ) : null}
) const PlanListItem = ({ plan }: { plan: ActionPlanListViewModel }) => (
  • {plan.title} {actionPlanKindLabels[plan.kind]} {plan.deputyPresent ? Deputado presente : null}

    {plan.startAt ? formatBahiaDateTimeLabel(plan.startAt) : 'Sem data definida'} {plan.locality ? ` · ${plan.locality}` : ''}

  • ) /** * E16 — "o que ler antes de entrar na cidade" (O6). A one-screen / 1–2 A4 * page pre-visit read: capa, conta local (série TSE + conta da cadeira), * rede, conjuntura (estratégia, dobradinhas, emendas), agenda, sinais e * perfil do eleitorado. Composes the same loaders/cards the other tabs use — * numbers, short lists and prose; no charts (anti-goal do discovery). */ export const MunicipalityDossier = ({ view, advisors, data, }: { view: MunicipalityDetailViewModel advisors: MunicipalityAdvisorSummary[] data: MunicipalityDossierData }) => { const strategy = view.strategy const trendStatus = strategy?.politicalTrend.status ?? null const goalAccount = data.goalAccount const usesMesaEstimate = strategy?.expectedVotes.central != null return (
    {/* Capa — self-contained so the printed dossier keeps its identity after the page header/tab chrome is hidden by print CSS. */}

    Dossiê — {view.name}

    Gerado em {formatBahiaDateTimeLabel(new Date().toISOString())}

    {municipalityKindLabels[view.kind]} · {formatMunicipalityGeographyLabel(view)}

    {strategy?.priority === 'alta' ? ( {municipalityPriorityLabels.alta} ) : ( Prioridade normal )} {trendStatus ? ( Tendência {politicalTrendLabels[trendStatus].toLowerCase()} ) : ( Tendência não registrada )}

    {advisors.length ? `Assessoria: ${advisors.map((advisor) => advisor.name).join(', ')}` : 'Sem assessor designado.'} {view.lastUpdateAt ? ` · Última atualização em ${dateFormatter.format(new Date(view.lastUpdateAt))}` : ''}

    {/* Conta local — série TSE (reuses the elections-tab card) + conta da cadeira. */} {goalAccount ? (
    Meta usada
    {formatElectionNumber(goalAccount.goalCoverage.goal)}
    {usesMesaEstimate ? 'estimativa da mesa' : 'meta sugerida'}
    Comprometido (pledges)
    {formatElectionNumber(goalAccount.goalCoverage.committed)}
    {data.pledgeAggregate.pledgeCount ? `${formatElectionNumber(data.pledgeAggregate.pledgeCount)} declaração(ões)` : 'nenhuma declaração'}
    Cobertura da meta
    {formatGoalCoverageRatioLabel(goalAccount.goalCoverage)}
    {formatGoalCoverageDeficitLabel(goalAccount.goalCoverage)}
    Captura (2022)
    {formatRatioAsPercentLabel(goalAccount.potential.captureRate2022)}
    do teto do campo:{' '} {formatElectionNumber(Math.round(goalAccount.potential.projectedFieldCeiling))}{' '} (proj.)
    ) : null} {/* Rede — quem receber/procurar na cidade, com frescor do cadastro. */}
    {data.leaderships.rows.length ? (
      {data.leaderships.rows.map((leadership) => (
    • {leadership.name} {leadership.supportStatus ? ( ) : null} {leadership.sector ? ( {leadership.sector} ) : null} {leadership.phone ? ( {leadership.phone} ) : null}
      {leadership.organizationNames.length ? ( {leadership.organizationNames.join(', ')} ) : null} atualizada em {dateFormatter.format(new Date(leadership.updatedAt))}
    • ))}
    ) : (

    Nenhuma liderança vinculada a este município ainda.

    )}
    {/* Conjuntura, dobradinhas, encaminhamentos e emendas — reuses the overview strategy card (emendas render only when preenchidas). */} {strategy ? ( ) : null} {/* Agenda — próximos eventos e últimas ações realizadas. */}
    {data.upcomingPlans.length ? (

    Próximos eventos

      {data.upcomingPlans.map((plan) => ( ))}
    ) : (

    Nenhum evento futuro planejado.

    )} {data.recentPlans.length ? (

    Últimas ações realizadas

      {data.recentPlans.map((plan) => ( ))}
    ) : null}
    {/* Sinais recentes — reuses the updates-tab feed presentation. */}
    {/* Perfil do eleitorado — IBGE Censo 2022 (A8). */} {data.demographics ? ( ) : null}
    ) } const DemographicsSection = ({ demographics, kind, city, }: { demographics: NonNullable kind: MunicipalityDetailViewModel['kind'] city: string }) => (
    População
    {formatElectionNumber(demographics.population)}
    Idade mediana
    {demographics.medianAge != null ? `${formatElectionNumber(demographics.medianAge)} anos` : '—'}
    Mulheres
    {formatRatioAsPercentLabel(demographics.sexShareFemale)}
    {(Object.keys(AGE_BAND_LABELS) as Array).map((band) => (
    {AGE_BAND_LABELS[band]}
    {formatElectionNumber(demographics.ageBands[band])}
    ))}
    {kind === 'zona' ? (

    Dados do município inteiro de {city} — o IBGE não divide o Censo por zona eleitoral.

    ) : null}
    )