import { EnvironmentalImpact as ImpactData, TransportEventType, TransportMethod } from '../../lib/transport/types'; interface EnvironmentalImpactProps { impact: ImpactData; title?: string; showDetails?: 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 EVENT_LABELS: Record = { seed_acquisition: 'Seed Acquisition', planting: 'Planting', growing_transport: 'Growing Transport', harvest: 'Harvest', processing: 'Processing', distribution: 'Distribution', consumer_delivery: 'Consumer Delivery', seed_saving: 'Seed Saving', seed_sharing: 'Seed Sharing', }; function getCarbonRating(carbon: number): { label: string; color: string; bgColor: string } { if (carbon < 0.5) return { label: 'Excellent', color: 'text-green-600', bgColor: 'bg-green-100' }; if (carbon < 1) return { label: 'Very Good', color: 'text-emerald-600', bgColor: 'bg-emerald-100' }; if (carbon < 2) return { label: 'Good', color: 'text-lime-600', bgColor: 'bg-lime-100' }; if (carbon < 5) return { label: 'Moderate', color: 'text-yellow-600', bgColor: 'bg-yellow-100' }; if (carbon < 10) return { label: 'High', color: 'text-orange-600', bgColor: 'bg-orange-100' }; return { label: 'Very High', color: 'text-red-600', bgColor: 'bg-red-100' }; } export default function EnvironmentalImpact({ impact, title = 'Environmental Impact Report', showDetails = true, }: EnvironmentalImpactProps) { const rating = getCarbonRating(impact.totalCarbonKg); // Sort methods by carbon impact const sortedMethods = Object.entries(impact.breakdownByMethod) .filter(([_, data]) => data.carbon > 0 || data.distance > 0) .sort((a, b) => b[1].carbon - a[1].carbon); // Sort events by count const sortedEvents = Object.entries(impact.breakdownByEventType) .filter(([_, data]) => data.count > 0) .sort((a, b) => b[1].count - a[1].count); const totalMethods = sortedMethods.length; const totalEvents = sortedEvents.reduce((sum, [_, data]) => sum + data.count, 0); return (
{/* Header */}

{title}

Complete carbon and food miles analysis

{/* Main metrics */}

{impact.totalCarbonKg.toFixed(2)}

Total Carbon (kg CO2)

{impact.totalFoodMiles.toFixed(1)}

Total Food Miles (km)

{impact.carbonPerKgProduce.toFixed(3)}

kg CO2 / kg Produce

{impact.milesPerKgProduce.toFixed(1)}

Miles / kg Produce

{/* Rating badge */}
Environmental Rating: {rating.label}
{/* Comparison with conventional */} {impact.comparisonToConventional && (

Comparison vs Conventional Agriculture

{impact.comparisonToConventional.percentageReduction.toFixed(0)}%

Carbon Reduction

{impact.comparisonToConventional.carbonSaved.toFixed(1)}

kg CO2 Saved

🌲 = {(impact.comparisonToConventional.carbonSaved / 21).toFixed(1)} trees/year

{impact.comparisonToConventional.milesSaved.toFixed(0)}

km Saved

🚗 = {(impact.comparisonToConventional.milesSaved / 15).toFixed(0)} car trips
{/* Visual bar comparison */}
Your Carbon Footprint {impact.totalCarbonKg.toFixed(2)} kg
Conventional Average {(impact.totalCarbonKg + impact.comparisonToConventional.carbonSaved).toFixed(2)} kg
)} {/* Detailed breakdowns */} {showDetails && (
{/* By Transport Method */} {sortedMethods.length > 0 && (

By Transport Method

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

{data.distance.toFixed(1)} km traveled

); })}
)} {/* By Event Type */} {sortedEvents.length > 0 && (

By Event Type

{sortedEvents.map(([eventType, data]) => { const percentage = totalEvents > 0 ? (data.count / totalEvents) * 100 : 0; return (
{EVENT_LABELS[eventType as TransportEventType] || eventType} {data.count} events • {data.carbon.toFixed(3)} kg
); })}
)}
)} {/* Tips Section */}

Tips to Reduce Impact

  • • Prefer walking, cycling, or electric vehicles for short distances
  • • Consolidate multiple transports into single trips
  • • Source from local producers within 25km when possible
  • • Use rail transport for longer distances when available
  • • Avoid air freight unless absolutely necessary
{/* Summary stats */}
Transport methods used: {totalMethods} Total events tracked: {totalEvents}
); }