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 (
{isReduction ? 'reduction in your carbon footprint' : 'increase in your carbon footprint'}
Current
{(originalEmission / TONNES_DIVISOR).toFixed(2)}
tonnes CO₂/year
Projected
{(projectedEmission / TONNES_DIVISOR).toFixed(2)}
tonnes CO₂/year
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) => (