import PropTypes from 'prop-types'; import { formatNumber } from '../../utils/formatters'; /** @constant {number} TONNES_DIVISOR - Converts kg to tonnes */ const TONNES_DIVISOR = 1000; /** @constant {number} TREE_ABSORPTION_KG - Approx kg CO₂ absorbed per tree per year */ const TREE_ABSORPTION_KG = 21; /** @constant {number} CAR_ANNUAL_EMISSION_KG - Approx kg CO₂ per car per year */ const CAR_ANNUAL_EMISSION_KG = 2000; /** @constant {number} SHORT_FLIGHT_EMISSION_KG - Approx kg CO₂ per short-haul flight */ const SHORT_FLIGHT_EMISSION_KG = 255; /** * ImpactDisplay — shows the projected impact of a simulation scenario * with before/after comparison and real-world equivalents. * @param {Object} props * @param {Object} props.simulation - The simulation result object * @returns {JSX.Element|null} */ export default function ImpactDisplay({ simulation }) { if (!simulation) return null; const { originalEmission, projectedEmission, reductionPercentage, annualSavingsKg } = simulation; const isReduction = annualSavingsKg > 0; return (

Impact Analysis

{/* Main result */}
{isReduction ? '▼' : '▲'} {Math.abs(reductionPercentage)}%

{isReduction ? 'reduction in your carbon footprint' : 'increase in your carbon footprint'}

{isReduction ? '🌍' : '⚠️'} {formatNumber(Math.abs(annualSavingsKg))} kg CO₂ {isReduction ? 'saved' : 'added'} per year
{/* Before/After */}

Current

{(originalEmission / TONNES_DIVISOR).toFixed(2)}

tonnes CO₂/year

Projected

{(projectedEmission / TONNES_DIVISOR).toFixed(2)}

tonnes CO₂/year

{/* Equivalents */} {isReduction && annualSavingsKg > 0 && (

That's equivalent to...

{[ { icon: '🌳', text: `${Math.round(annualSavingsKg / TREE_ABSORPTION_KG)} trees absorbing CO₂ for a year`, }, { icon: '🚗', text: `Removing ${(annualSavingsKg / CAR_ANNUAL_EMISSION_KG).toFixed(1)} cars from the road`, }, { icon: '✈️', text: `${(annualSavingsKg / SHORT_FLIGHT_EMISSION_KG).toFixed(1)} fewer short-haul flights`, }, ].map((eq) => (
{eq.text}
))}
)}
); } ImpactDisplay.propTypes = { simulation: PropTypes.shape({ originalEmission: PropTypes.number.isRequired, projectedEmission: PropTypes.number.isRequired, reductionPercentage: PropTypes.number.isRequired, annualSavingsKg: PropTypes.number.isRequired, scenarioName: PropTypes.string, categoryBreakdown: PropTypes.object, }), };