import { cn } from '@/lib/utils' import { formatVoteEstimateScenarioAriaLabel, VOTE_ESTIMATE_SCENARIOS, voteEstimateScenarioLabels, type VoteEstimateScenario, type VoteEstimateScenarioViewModel, } from '@/utilities/voteEstimate' const voteFormatter = new Intl.NumberFormat('pt-BR') type VoteEstimateScenarioStripProps = { values: VoteEstimateScenarioViewModel activeScenario?: VoteEstimateScenario className?: string /** @deprecated Prefer labelMode */ showLabels?: boolean labelMode?: 'all' | 'endpoints' | 'none' markerMode?: 'all' | 'active-only' stretch?: boolean } export const VoteEstimateScenarioStrip = ({ values, activeScenario = 'central', className, showLabels = true, labelMode, markerMode = 'all', stretch = false, }: VoteEstimateScenarioStripProps) => { const resolvedLabelMode = labelMode ?? (showLabels ? 'all' : 'none') const activeOnlyMarkers = markerMode === 'active-only' const trackClassName = stretch ? 'w-full min-w-0 max-w-none' : 'w-full min-w-[4.5rem] max-w-[5.5rem]' const filled = VOTE_ESTIMATE_SCENARIOS.map((scenario) => values[scenario]).filter( (value): value is number => value != null, ) const min = filled.length > 0 ? Math.min(...filled) : null const max = filled.length > 0 ? Math.max(...filled) : null const hasSpread = min != null && max != null && max > min const activeValue = values[activeScenario] const activeMarkerPosition = activeValue != null && min != null && max != null ? hasSpread ? ((activeValue - min) / (max - min)) * 100 : 50 : null const activeMarker = activeMarkerPosition != null ? ( ) : null return (
{activeOnlyMarkers ? (
{activeMarker}
) : hasSpread ? (
{VOTE_ESTIMATE_SCENARIOS.map((scenario) => { const value = values[scenario] if (value == null) return null const position = ((value - min) / (max - min)) * 100 const isActive = scenario === activeScenario return ( ) })}
) : (
{VOTE_ESTIMATE_SCENARIOS.map((scenario) => { const value = values[scenario] const isActive = scenario === activeScenario return ( ) })}
)} {resolvedLabelMode === 'all' ? (
{VOTE_ESTIMATE_SCENARIOS.map((scenario) => { const value = values[scenario] return ( {value == null ? '·' : voteFormatter.format(value)} ) })}
) : resolvedLabelMode === 'endpoints' ? (
{values.pessimistic == null ? '·' : voteFormatter.format(values.pessimistic)} {values.optimistic == null ? '·' : voteFormatter.format(values.optimistic)}
) : null}
) }