import Link from 'next/link' import type { BahiaMapFeatureInfo } from '@/components/campaign/BahiaMap' import { Button } from '@/components/ui/button' import { formatElectionNumber } from '@/lib/electionInsights' import type { MunicipalityMapNavigation } from '@/utilities/municipalityMapNavigation' import type { MunicipalityMapScaleMode } from '@/utilities/municipalityMapContract' type MapFeatureReadoutProps = { feature: BahiaMapFeatureInfo | null metricValue: number | undefined rawMetricValue: number | undefined metricLabel: string scaleMode: MunicipalityMapScaleMode comparisonActive: boolean navigation: MunicipalityMapNavigation | null } const percentFormatter = new Intl.NumberFormat('pt-BR', { style: 'percent', maximumFractionDigits: 1, }) const formatMetricValue = ( value: number | undefined, scaleMode: MunicipalityMapScaleMode, comparisonActive: boolean, ): string => { if (value === undefined) return 'Sem dados' if (comparisonActive) { const prefix = value > 0 ? '+' : '' return `${prefix}${formatElectionNumber(value)}` } if (scaleMode === 'percentValid') return percentFormatter.format(value) return formatElectionNumber(value) } export const MapFeatureReadout = ({ feature, metricValue, rawMetricValue, metricLabel, scaleMode, comparisonActive, navigation, }: MapFeatureReadoutProps) => { if (!feature) { return (
Passe o cursor ou toque em um município para ver os votos.
) } const formattedValue = formatMetricValue(metricValue, scaleMode, comparisonActive) const showPercentSecondary = !comparisonActive && scaleMode === 'percentValid' && metricValue !== undefined && rawMetricValue !== undefined && rawMetricValue > 0 return ({feature.name}
{metricLabel}: {formattedValue} {!comparisonActive && metricValue !== undefined && scaleMode === 'absolute' ? ( {metricLabel} ) : null} {!comparisonActive && metricValue !== undefined && scaleMode === 'percentValid' ? ( dos válidos ) : null} {comparisonActive && metricValue !== undefined ? ( (diferença) ) : null}
{showPercentSecondary ? ({formatElectionNumber(rawMetricValue)} votos
) : null} {navigation?.kind === 'zones' ? (Toque de novo no mapa ou role até as Praças por zona abaixo.
) : null}