'use client' import { useEffect, useRef, useState } from 'react' import { CampaignMetricStrip } from '@/components/campaign/CampaignMetricStrip' import { campaignPrioritySurfaceClassName } from '@/components/campaign/CampaignPageShell' import { usePlazaEstimateScenario } from '@/components/campaign/PlazaEstimateScenarioContext' import { VOTE_ESTIMATE_SCENARIO_OVERVIEW_HINT, VoteEstimateScenarioField, } from '@/components/campaign/VoteEstimateScenarioField' import { VoteEstimateScenarioStrip } from '@/components/campaign/VoteEstimateScenarioStrip' import { formatElectionNumber } from '@/lib/electionInsights' import { cn } from '@/lib/utils' import type { PlazaListOverviewData } from '@/utilities/plazaPageData' import { formatVoteEstimateEndpointsLabel, hasAnyVoteEstimate, voteEstimateScenarioLabels, } from '@/utilities/voteEstimate' const SCENARIO_FLASH_MS = 420 export const PlazaListOverview = ({ view }: { view: PlazaListOverviewData }) => { const { scenario, setScenario } = usePlazaEstimateScenario() const [isFlashing, setIsFlashing] = useState(false) const skipFlashRef = useRef(true) const flashTimeoutRef = useRef | undefined>(undefined) useEffect(() => { if (skipFlashRef.current) { skipFlashRef.current = false return } const reduceMotion = typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches if (reduceMotion) return setIsFlashing(true) clearTimeout(flashTimeoutRef.current) flashTimeoutRef.current = setTimeout(() => setIsFlashing(false), SCENARIO_FLASH_MS) return () => clearTimeout(flashTimeoutRef.current) }, [scenario]) const scenarioTotals = view.staffVoteTotalByScenario const activeTotal = scenarioTotals[scenario] const endpointsLabel = formatVoteEstimateEndpointsLabel(scenarioTotals) const scenarioLabel = voteEstimateScenarioLabels[scenario] const hasScenarioTotals = hasAnyVoteEstimate(scenarioTotals) const heroDetail = (
{hasScenarioTotals ? ( ) : null} {endpointsLabel ? (

{endpointsLabel}

) : null} {view.missingEstimateCount > 0 ? (

{formatElectionNumber(view.missingEstimateCount)}{' '} {view.missingEstimateCount === 1 ? 'declaração' : 'declarações'} sem estimativa

) : null}
) return (
0 ? `; ${formatElectionNumber(view.missingEstimateCount)} sem estimativa` : '' }`, }, { label: 'Declarações de votos', value: view.pledgeCount ? formatElectionNumber(view.pledgeCount) : 'Nenhuma', }, { label: 'Cobertura de assessoria', value: `${view.withAdvisorCount} de ${view.plazaCount} Praças`, progress: view.plazaCount > 0 ? Math.round((view.withAdvisorCount / view.plazaCount) * 100) : undefined, }, ]} />
) }