import { EnvironmentalImpact, TransportMethod } from '../../lib/transport/types'; interface CarbonFootprintCardProps { impact: EnvironmentalImpact; showComparison?: boolean; } const METHOD_LABELS: Record = { walking: 'Walking', bicycle: 'Bicycle', electric_vehicle: 'Electric Vehicle', hybrid_vehicle: 'Hybrid Vehicle', gasoline_vehicle: 'Gas Vehicle', diesel_truck: 'Diesel Truck', electric_truck: 'Electric Truck', refrigerated_truck: 'Refrigerated Truck', rail: 'Rail', ship: 'Ship', air: 'Air Freight', drone: 'Drone', local_delivery: 'Local Delivery', customer_pickup: 'Customer Pickup', }; const METHOD_COLORS: Record = { walking: 'bg-green-500', bicycle: 'bg-green-400', electric_vehicle: 'bg-emerald-400', hybrid_vehicle: 'bg-lime-400', electric_truck: 'bg-teal-400', drone: 'bg-cyan-400', rail: 'bg-blue-400', ship: 'bg-blue-500', local_delivery: 'bg-yellow-400', customer_pickup: 'bg-orange-400', gasoline_vehicle: 'bg-orange-500', diesel_truck: 'bg-red-400', refrigerated_truck: 'bg-red-500', air: 'bg-red-600', }; export default function CarbonFootprintCard({ impact, showComparison = true }: CarbonFootprintCardProps) { // Calculate breakdown percentages const totalCarbon = impact.totalCarbonKg; const methodBreakdown = Object.entries(impact.breakdownByMethod) .filter(([_, data]) => data.carbon > 0) .sort((a, b) => b[1].carbon - a[1].carbon); const getCarbonRating = (carbon: number): { label: string; color: string; icon: string } => { if (carbon < 0.5) return { label: 'Excellent', color: 'text-green-600', icon: '🌟' }; if (carbon < 2) return { label: 'Good', color: 'text-lime-600', icon: '✓' }; if (carbon < 5) return { label: 'Moderate', color: 'text-yellow-600', icon: '⚡' }; if (carbon < 10) return { label: 'High', color: 'text-orange-600', icon: '⚠️' }; return { label: 'Very High', color: 'text-red-600', icon: '🚨' }; }; const rating = getCarbonRating(totalCarbon); return (
{/* Header */}

Carbon Footprint

Environmental impact analysis

{totalCarbon.toFixed(2)}
kg CO2e
{/* Rating badge */}
{rating.icon} {rating.label}
{/* Key metrics */}

Total Food Miles

{impact.totalFoodMiles.toFixed(1)}

kilometers

Carbon Intensity

{impact.carbonPerKgProduce.toFixed(3)}

kg CO2 / kg produce

{/* Comparison with conventional */} {showComparison && impact.comparisonToConventional && (

📊 vs. Conventional Agriculture

Carbon Saved {impact.comparisonToConventional.carbonSaved.toFixed(2)} kg
Miles Saved {impact.comparisonToConventional.milesSaved.toFixed(1)} km
{impact.comparisonToConventional.percentageReduction.toFixed(0)}% reduction vs conventional
)} {/* Breakdown by transport method */} {methodBreakdown.length > 0 && (

Breakdown by Transport Method

{methodBreakdown.map(([method, data]) => { const percentage = totalCarbon > 0 ? (data.carbon / totalCarbon) * 100 : 0; return (
{METHOD_LABELS[method as TransportMethod] || method}
{data.carbon.toFixed(3)} kg ({percentage.toFixed(0)}%)
); })}
)} {/* Tips */}

Tips to Reduce Impact

    {totalCarbon > 5 && (
  • • Consider electric or hybrid vehicles for transport
  • )} {impact.totalFoodMiles > 50 && (
  • • Source produce from closer locations when possible
  • )}
  • • Consolidate shipments to reduce trips
  • • Use bicycle delivery for short distances
); }