import { useState, useEffect } from 'react'; import { GrowingEnvironment } from '../lib/environment/types'; import { EnvironmentalRecommendation } from '../lib/environment/types'; interface EnvironmentalDisplayProps { environment: GrowingEnvironment; plantId: string; showRecommendations?: boolean; } export default function EnvironmentalDisplay({ environment, plantId, showRecommendations = true, }: EnvironmentalDisplayProps) { const [recommendations, setRecommendations] = useState([]); const [healthScore, setHealthScore] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (showRecommendations) { fetchRecommendations(); } }, [plantId]); const fetchRecommendations = async () => { try { const response = await fetch(`/api/environment/recommendations?plantId=${plantId}`); const data = await response.json(); if (data.success) { setRecommendations(data.recommendations); setHealthScore(data.environmentalHealth); } } catch (error) { console.error('Error fetching recommendations:', error); } finally { setLoading(false); } }; return (
{/* Environmental Health Score */} {healthScore !== null && (

Environmental Health Score

Overall assessment of growing conditions

{healthScore}
/ 100

{getScoreInterpretation(healthScore)}

)} {/* Recommendations */} {showRecommendations && recommendations.length > 0 && (

๐Ÿ“‹ Recommendations ({recommendations.length})

{recommendations.map((rec, idx) => ( ))}
)} {/* Soil Information */}

๐ŸŒฑ Soil Composition

{/* Climate Conditions */}

๐ŸŒก๏ธ Climate Conditions

{environment.climate.zone && ( )}
{/* Lighting */}

โ˜€๏ธ Lighting

{environment.lighting.naturalLight && ( <> )} {environment.lighting.artificialLight && ( <> )}
{/* Location & Container */}

๐Ÿ“ Location

{environment.location.room && ( )} {environment.location.elevation && ( )}
{environment.container && (

๐Ÿชด Container

{environment.container.material && ( )} {environment.container.size && ( )}
)}
{/* Watering */}

๐Ÿ’ง Watering

{environment.watering.frequency && ( )} {environment.watering.waterQuality?.pH && ( )}
{/* Nutrients */} {environment.nutrients && (

๐Ÿงช Nutrients

{environment.nutrients.ec && ( )} {environment.nutrients.tds && ( )}
)} {/* Surroundings */} {environment.surroundings && (

๐ŸŒฟ Surroundings

{environment.surroundings.ecosystem && ( )} {environment.surroundings.windExposure && ( )} {environment.surroundings.companionPlants && environment.surroundings.companionPlants.length > 0 && (

Companion Plants:

{environment.surroundings.companionPlants.join(', ')}

)}
)}
); } function RecommendationCard({ recommendation }: { recommendation: EnvironmentalRecommendation }) { const priorityColors = { critical: 'border-red-500 bg-red-50', high: 'border-orange-500 bg-orange-50', medium: 'border-yellow-500 bg-yellow-50', low: 'border-blue-500 bg-blue-50', }; const priorityIcons = { critical: '๐Ÿšจ', high: 'โš ๏ธ', medium: '๐Ÿ’ก', low: 'โ„น๏ธ', }; return (
{priorityIcons[recommendation.priority]}

{recommendation.issue}

{recommendation.priority}

Recommendation: {recommendation.recommendation}

Impact: {recommendation.impact}

); } function DataPoint({ label, value, highlight, }: { label: string; value: string; highlight?: 'red' | 'green'; }) { const highlightClass = highlight === 'red' ? 'text-red-600 font-semibold' : highlight === 'green' ? 'text-green-600 font-semibold' : ''; return (

{label}

{value}

); } function formatValue(value: string): string { return value.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase()); } function getScoreColor(score: number): string { if (score >= 90) return 'text-green-600'; if (score >= 75) return 'text-lime-600'; if (score >= 60) return 'text-yellow-600'; if (score >= 40) return 'text-orange-600'; return 'text-red-600'; } function getScoreBgColor(score: number): string { if (score >= 90) return 'bg-green-600'; if (score >= 75) return 'bg-lime-600'; if (score >= 60) return 'bg-yellow-600'; if (score >= 40) return 'bg-orange-600'; return 'bg-red-600'; } function getScoreInterpretation(score: number): string { if (score >= 90) return '๐ŸŒŸ Excellent conditions - your plant should thrive!'; if (score >= 75) return 'โœ“ Good conditions with minor room for improvement'; if (score >= 60) return 'โšก Adequate conditions, several optimization opportunities'; if (score >= 40) return 'โš ๏ธ Suboptimal conditions, address high-priority issues'; return '๐Ÿšจ Poor conditions, immediate action needed'; }