/** * CarbonImpactComparison Component * * Displays varied carbon offset impact comparisons with animations. * Uses EPA/DEFRA/IMO 2024 verified conversion factors. */ import { motion, useInView } from 'framer-motion'; import { useRef } from 'react'; import * as LucideIcons from 'lucide-react'; import { selectComparisons } from '../utils/impactSelector'; import type { CarbonComparison } from '../types/carbonEquivalencies'; interface CarbonImpactComparisonProps { /** Metric tons of CO2e being offset */ tons: number; /** Display variant */ variant?: 'preview' | 'success'; /** Number of comparisons to show (default: 3) */ count?: number; /** Additional CSS classes */ className?: string; } /** * Animated counter component with count-up effect */ interface AnimatedCounterProps { value: number; duration?: number; } function AnimatedCounter({ value, duration = 2 }: AnimatedCounterProps) { const ref = useRef(null); const isInView = useInView(ref, { once: true, amount: 0.5 }); return ( {isInView && ( {value.toLocaleString()} )} ); } /** * Get Lucide icon component by name */ function getLucideIcon(iconName: string): React.ElementType { const Icon = (LucideIcons as Record)[iconName]; return Icon || LucideIcons.Leaf; // Fallback to Leaf icon } /** * Individual comparison card component */ interface ComparisonCardProps { comparison: CarbonComparison; index: number; } function ComparisonCard({ comparison, index }: ComparisonCardProps) { const Icon = getLucideIcon(comparison.icon); return ( {/* Icon */}
{/* Value */}
{comparison.unit}
{/* Label */}

{comparison.label}

{comparison.description && (

{comparison.description}

)}
{/* Source */}
Source: {comparison.source}
); } /** * Main CarbonImpactComparison component */ export function CarbonImpactComparison({ tons, variant = 'preview', count = 3, className = '', }: CarbonImpactComparisonProps) { // Get appropriate comparisons for this CO2 amount const comparisons = selectComparisons(tons, count); // Variant-specific styling const titleText = variant === 'success' ? 'Your Impact' : 'Making an Impact'; const subtitleText = variant === 'success' ? "Here's what your offset is equivalent to:" : 'Your carbon offset is equivalent to:'; return (
{/* Header */}

{titleText}

{subtitleText}

{/* Comparison Cards Grid */}
{comparisons.map((comparison, index) => ( ))}
{/* Footer Note */}

Equivalencies calculated using EPA 2024, DEFRA 2024, and IMO 2024 verified conversion factors.

); } export default CarbonImpactComparison;