import { useState } from 'react'; import { GrowingEnvironment, SoilComposition, ClimateConditions, LightingConditions, NutrientProfile, WateringSchedule, ContainerInfo, EnvironmentLocation, SurroundingEnvironment, } from '../lib/environment/types'; interface EnvironmentalFormProps { value: Partial; onChange: (env: Partial) => void; compact?: boolean; } export default function EnvironmentalForm({ value, onChange, compact = false, }: EnvironmentalFormProps) { const [activeSection, setActiveSection] = useState('soil'); const updateSection = ( section: K, updates: Partial ) => { onChange({ ...value, [section]: { ...value[section], ...updates, }, }); }; const sections = [ { id: 'soil', name: '๐ŸŒฑ Soil', icon: '๐ŸŒฑ' }, { id: 'nutrients', name: '๐Ÿงช Nutrients', icon: '๐Ÿงช' }, { id: 'lighting', name: 'โ˜€๏ธ Light', icon: 'โ˜€๏ธ' }, { id: 'climate', name: '๐ŸŒก๏ธ Climate', icon: '๐ŸŒก๏ธ' }, { id: 'location', name: '๐Ÿ“ Location', icon: '๐Ÿ“' }, { id: 'container', name: '๐Ÿชด Container', icon: '๐Ÿชด' }, { id: 'watering', name: '๐Ÿ’ง Water', icon: '๐Ÿ’ง' }, { id: 'surroundings', name: '๐ŸŒฟ Surroundings', icon: '๐ŸŒฟ' }, ]; return (
{/* Section Tabs */}
{sections.map((section) => ( ))}
{/* Section Content */}
{activeSection === 'soil' && ( updateSection('soil', soil)} /> )} {activeSection === 'nutrients' && ( updateSection('nutrients', nutrients)} /> )} {activeSection === 'lighting' && ( updateSection('lighting', lighting)} /> )} {activeSection === 'climate' && ( updateSection('climate', climate)} /> )} {activeSection === 'location' && ( updateSection('location', location)} /> )} {activeSection === 'container' && ( updateSection('container', container)} /> )} {activeSection === 'watering' && ( updateSection('watering', watering)} /> )} {activeSection === 'surroundings' && ( updateSection('surroundings', surroundings)} /> )}
); } // Soil Section Component function SoilSection({ value, onChange, }: { value?: Partial; onChange: (soil: Partial) => void; }) { const soil = value || {}; return (

Soil Composition

onChange({ ...soil, pH: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
{soil.pH && soil.pH < 5.5 && 'โš ๏ธ Acidic - may need lime'} {soil.pH && soil.pH >= 5.5 && soil.pH <= 7.5 && 'โœ“ Good range'} {soil.pH && soil.pH > 7.5 && 'โš ๏ธ Alkaline - may need sulfur'}
onChange({ ...soil, organicMatter: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />

๐Ÿ’ก Tip: Test soil pH with a meter or test kit for accuracy. Most vegetables prefer pH 6.0-7.0.

); } // Nutrients Section Component function NutrientsSection({ value, onChange, }: { value?: Partial; onChange: (nutrients: Partial) => void; }) { const nutrients = value || {}; return (

Nutrient Profile

Primary Nutrients (NPK)

onChange({ ...nutrients, nitrogen: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
onChange({ ...nutrients, phosphorus: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
onChange({ ...nutrients, potassium: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />

NPK ratio: {nutrients.nitrogen || 0}-{nutrients.phosphorus || 0}-{nutrients.potassium || 0}

๐Ÿ’ก Tip: Leave at 0 if unknown. Use soil test kit for accurate NPK values.

); } // Lighting Section Component function LightingSection({ value, onChange, }: { value?: Partial; onChange: (lighting: Partial) => void; }) { const lighting = value || { type: 'natural' }; return (

Lighting Conditions

{(lighting.type === 'natural' || lighting.type === 'mixed') && (
onChange({ ...lighting, naturalLight: { ...lighting.naturalLight, hoursPerDay: parseInt(e.target.value), } as any, }) } className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
)}

๐Ÿ’ก Tip: Most vegetables need 6+ hours of direct sunlight. Herbs can do well with 4-6 hours.

); } // Climate Section Component function ClimateSection({ value, onChange, }: { value?: Partial; onChange: (climate: Partial) => void; }) { const climate = value || {}; return (

Climate Conditions

onChange({ ...climate, temperatureDay: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
onChange({ ...climate, temperatureNight: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />
onChange({ ...climate, humidityAverage: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />

๐Ÿ’ก Tip: Most plants thrive at 18-25ยฐC. Good airflow prevents disease.

); } // Location Section Component function LocationSection({ value, onChange, }: { value?: Partial; onChange: (location: Partial) => void; }) { const location = value || {}; return (

Growing Location

๐Ÿ’ก Tip: Location type affects climate control and pest exposure.

); } // Container Section Component function ContainerSection({ value, onChange, }: { value?: Partial; onChange: (container: Partial) => void; }) { const container = value || {}; return (

Container Information

{container.drainage === 'no' && (

โš ๏ธ WARNING: No drainage will likely kill your plant!

)}
onChange({ ...container, size: e.target.value })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />

๐Ÿ’ก Tip: Always ensure drainage! Sitting water = root rot = dead plant.

); } // Watering Section Component function WateringSection({ value, onChange, }: { value?: Partial; onChange: (watering: Partial) => void; }) { const watering = value || {}; return (

Watering Schedule

onChange({ ...watering, frequency: e.target.value })} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500" />

๐Ÿ’ก Tip: Water when top inch of soil is dry. Overwatering kills more plants than underwatering!

); } // Surroundings Section Component function SurroundingsSection({ value, onChange, }: { value?: Partial; onChange: (surroundings: Partial) => void; }) { const surroundings = value || {}; return (

Surrounding Environment

๐Ÿ’ก Tip: Track companion plants and pests to learn what works in your ecosystem.

); }