import { ArrowRightIcon } from 'lucide-react' import Link from 'next/link' import type { ReactNode } from 'react' import { NearestMunicipalityCard } from '@/components/campaign/dashboard/NearestMunicipalityCard' import { RecentlyVisitedCard } from '@/components/campaign/dashboard/RecentlyVisitedCard' import { CampaignMetricStrip } from '@/components/campaign/shared/CampaignMetricStrip' import { CampaignPageShell, campaignPrioritySurfaceClassName, } from '@/components/campaign/shell/CampaignPageShell' import { Badge } from '@/components/ui/Badge' import { Button } from '@/components/ui/button' import { municipalityForCode } from '@/lib/bahiaMunicipalityCodes' import { formatElectionNumber } from '@/lib/electionFormat' import type { AccessibleMunicipality } from '@/lib/municipalityProximity' import { formatVoteEstimateEndpointsLabel, voteEstimateScenarioLabels } from '@/lib/voteEstimate' import type { StaffDashboardView } from '@/utilities/campaignDashboardData' import { formatGoalCoverageDeficitLabel, formatGoalCoverageRatioLabel, goalCoverageProgressPercent, } from '@/utilities/municipality/goalCoverage' import { buildMunicipalityListHref } from '@/utilities/municipality/municipalityListUrl' import { buildMunicipalitiesByIbgeCode } from '@/utilities/municipality/municipalityMapNavigation' const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', { dateStyle: 'short', timeStyle: 'short', }) /** * B14 — one filtered-list href per city the catalog splits into zone municipalities * (today only Salvador), for the cities where the actor can open more than one zone. * Serialized here rather than in the island: the canonical list-URL builder validates * against the catalog and the identity-territory table, and importing it into a client * component added 21 KB to this route's First Load JS for a single link. * * The search term is the whole-city name, which matches every `Salvador — ZE n` row * and is then scoped by the list to what the actor may read. */ const buildZoneCityHrefs = ( accessible: readonly AccessibleMunicipality[], ): Record => { const hrefs: Record = {} for (const [ibgeCode, entries] of Object.entries(buildMunicipalitiesByIbgeCode(accessible))) { if (entries.length < 2) continue const city = municipalityForCode(ibgeCode) if (city) hrefs[ibgeCode] = buildMunicipalityListHref({ page: 1, q: city }, 1) } return hrefs } export const CampaignDashboard = ({ view, userName, mapSlot = null, suggestionsSlot = null, }: { view: StaffDashboardView userName: string /** Server-streamed map section (composition keeps this component map-agnostic). */ mapSlot?: ReactNode /** Server-streamed suggestion queue (E11) — right after the KPIs: it is the "onde ajo". */ suggestionsSlot?: ReactNode }) => (

Olá, {userName}

{view.role === 'advisor' ? 'Quadro dos municípios sob sua assessoria.' : 'Quadro geral da campanha por município.'}

{mapSlot}
0 ? Math.round((view.withAdvisorCount / view.municipalityCount) * 100) : undefined, }, { label: 'Cobertura da meta', value: formatGoalCoverageRatioLabel(view.goalCoverage), detail: formatGoalCoverageDeficitLabel(view.goalCoverage), progress: goalCoverageProgressPercent(view.goalCoverage), }, { label: 'Declarações sem estimativa', value: formatElectionNumber(view.missingEstimateCount), }, ]} />
{suggestionsSlot}

Declarações aguardando estimativa

{view.missingEstimateCount}
{view.missingEstimates.length ? (
    {view.missingEstimates.map((item) => (
  • {item.contactName} {item.municipalityName} · declarou {formatElectionNumber(item.declaredVotes)}{' '} votos
  • ))}
) : (

Todas as declarações do seu escopo têm estimativa registrada.

)}

Últimas atualizações de campo

{view.recentUpdates.length ? (
    {view.recentUpdates.map((update) => (
  • {update.municipalityName} {update.authorName} · {dateTimeFormatter.format(new Date(update.createdAt))}
  • ))}
) : (

Nenhuma atualização registrada ainda.

)}
{view.priorityMunicipalities.length ? (

Municípios prioritários

{view.highPriorityCount}
{view.highPriorityCount > view.priorityMunicipalities.length ? ( ) : null}
    {view.priorityMunicipalities.map((municipality) => (
  • ))}
) : null} {/* * Navigation shortcuts. Both cards decide for themselves whether they have * anything to say — recent visits are empty on a fresh device, and the geo * card hides when the browser cannot help — so the row disappears in CSS * (`has-[>*]`) instead of asking the islands to report visibility upward, * which cost two state slots and a layout shift on every load. Two columns * even with a single card, keeping the width rhythm of the panels above. */}
)