{formatVoteSharePercent(share)}{formatElectionNumber(votes)}
{/* The valid votes live only in the hover — keep them as sr-only text so the tooltip repeats, never invents. */}
Votos válidos de deputado federal em 2022 no território:{' '}
{formatElectionNumber(row.validVotes2022)}
)
}
/** B175 — 2026 read-only cell: central-scenario total + % as a secondary line; scenarios on hover. */
const TerritoryEstimateReadout = ({ row }: { row: TerritoryTableRow }) => {
if (!row.hasEstimate) {
return —
}
return (
{formatElectionNumber(row.estimateByScenario.central)}
{formatVoteSharePercent(row.pctPropriaVotacao)}
{/* Same redundancy contract as the cell's hover strip (municípios precedent). */}
{formatVoteEstimateScenarioAriaLabel(row.estimateByScenario)}
)
}
// ---------------------------------------------------------------------------
// B175 — read-only network columns (Assessor / Liderança / Dobradinha)
// ---------------------------------------------------------------------------
const territoryNetworkColumnDescriptions = {
advisor:
'Assessores de staff atribuídos nos municípios do território. Nomes no detalhe da célula.',
leadership: 'Lideranças vinculadas aos municípios do território. Nomes no detalhe da célula.',
stateDeputy:
'Deputados estaduais em dobradinha nos municípios do território. Nomes no detalhe da célula.',
} as const
const territoryNetworkColumnLabels = {
advisor: 'Assessor',
leadership: 'Liderança',
stateDeputy: 'Dobradinha',
} as const
const advisorEntries = (
row: TerritoryTableRow,
advisorNamesById: TerritoryNetworkReferences['advisorNamesById'],
): MunicipalityRelationEntry[] =>
row.advisorIDs.flatMap((id) => {
const advisor = advisorNamesById.get(id)
return advisor ? [{ id: advisor.id, label: advisor.name }] : []
})
const leadershipEntries = (
row: TerritoryTableRow,
leadershipNamesById: TerritoryNetworkReferences['leadershipNamesById'],
): MunicipalityRelationEntry[] =>
row.leadershipIDs.flatMap((id) => {
const leadership = leadershipNamesById.get(id)
return leadership
? [
{
id: leadership.id,
label: leadership.name,
href: `/campanha/liderancas/${leadership.id}`,
},
]
: []
})
const stateDeputyEntries = (
row: TerritoryTableRow,
stateDeputyById: TerritoryNetworkReferences['stateDeputyById'],
): MunicipalityRelationEntry[] =>
row.stateDeputyIDs.flatMap((id) => {
const deputy: TerritoryStateDeputyReference | undefined = stateDeputyById.get(id)
if (!deputy) return []
return [
{
id: deputy.id,
label: stateDeputyDisplayName(deputy.plainName, deputy.party),
initialsLabel: deputy.plainName,
href: deputy.href,
},
]
})
const namesTooltip = (entries: MunicipalityRelationEntry[]): ReactElement | null =>
entries.length === 0 ? null : (
{entries.map((entry) => (
{entry.label}
))}
)
const NetworkCell = ({ entries }: { entries: MunicipalityRelationEntry[] }) => (
—}
maxVisible={3}
/>
)
/**
* B175 — column widths keep the density ladder: P0 core is always on, one
* column joins per panel-width rung, never a horizontal scrollbar.
*/
const responsiveColumnClassName = {
captura: 'hidden @min-[44rem]/territory-list:table-cell',
classe: 'hidden @min-[50rem]/territory-list:table-cell',
coverage: 'hidden @min-[54rem]/territory-list:table-cell',
advisor: 'hidden @min-[60rem]/territory-list:table-cell',
leadership: 'hidden @min-[66rem]/territory-list:table-cell',
stateDeputy: 'hidden @min-[72rem]/territory-list:table-cell',
cobertura: 'hidden @min-[78rem]/territory-list:table-cell',
} as const
type TerritoryListColumnsProps = {
state: TerritoryListState
regionOptions: TerritoryFilterOption[]
references: TerritoryNetworkReferences
}
export const territoryListColumns = ({
state,
regionOptions,
references,
}: TerritoryListColumnsProps): Array> => {
const { advisorNamesById, leadershipNamesById, stateDeputyById } = references
return [
{
id: 'region',
mandatory: true,
label: territoryListSortLabels.region,
head: (
),
cell: (row) =>
row.variant === 'parent' ? (
{row.region}{' '}
({row.municipalityCount})
) : (
// The Metropolitano sub-labels already carry a count group ("Salvador (19 zonas)"),
// so the count rides the name only when the label has none — never stacking "(19 zonas) (19)".
{row.label}{' '}
{/\(\d[^)]*\)$/.test(row.label) ? null : (
({row.municipalityCount})
)}
),
cellClassName: (row) =>
`sticky left-0 z-[5] min-w-56 ${row.variant === 'sub' ? 'bg-muted' : 'bg-background'}`,
},
{
id: 'votes2022',
label: territoryListSortLabels.votes2022,
head: (
),
cell: (row) => ,
cellClassName: 'text-right tabular-nums',
// The valid-votes figure is the cell's exclusive hover content (B175).
cellTooltip: (row) =>
`Votos válidos de deputado federal em 2022 no território: ${formatElectionNumber(row.validVotes2022)}`,
},
{
id: 'captura',
label: territoryListSortLabels.captura,
head: (
),
cell: (row) => formatRatioAsPercentLabel(row.captureRate),
cellClassName: (row) =>
`${responsiveColumnClassName.captura} text-right tabular-nums ${
row.variant !== 'parent' ? 'text-muted-foreground' : ''
}`,
cellTooltip: (row) => captureTooltipContent(row),
},
{
id: 'estimate2026',
label: territoryListSortLabels.estimate2026,
head: (
),
cell: (row) => ,
cellClassName: (row) =>
`text-right tabular-nums ${row.variant === 'sub' ? 'text-muted-foreground' : ''}`,
cellTooltip: (row) =>
row.hasEstimate ? (