import { useState } from 'react'; import { Bed } from './GrowRoomHeatmap'; import BedTooltip from './BedTooltip'; /** * BedCell - Individual bed cell in the grid * * Renders a single bed with color-coded health score. * Shows tooltip on hover with detailed bed information. * * Color scale: * - 90-100: Dark green (excellent) * - 70-89: Light green (good) * - 50-69: Yellow (fair) * - 30-49: Orange (needs attention) * - 0-29: Red (critical) * - Empty: Gray outline (no plant) */ interface BedCellProps { bed?: Bed; x: number; y: number; size: number; row: number; column: number; } export default function BedCell({ bed, x, y, size, row, column }: BedCellProps) { const [showTooltip, setShowTooltip] = useState(false); const [tooltipPosition, setTooltipPosition] = useState({ x: 0, y: 0 }); // Get color based on health score const getHealthColor = (score: number): string => { if (score >= 90) return '#059669'; // emerald-600 if (score >= 70) return '#10b981'; // emerald-500 if (score >= 50) return '#eab308'; // yellow-500 if (score >= 30) return '#f97316'; // orange-500 return '#dc2626'; // red-600 }; const handleMouseEnter = (e: React.MouseEvent) => { if (bed && bed.status !== 'empty') { setTooltipPosition({ x: e.clientX, y: e.clientY }); setShowTooltip(true); } }; const handleMouseLeave = () => { setShowTooltip(false); }; const handleClick = () => { if (bed && bed.status !== 'empty') { // TODO: Navigate to bed detail page console.log('Navigate to bed:', bed.bed_id); } }; // Empty bed if (!bed || bed.status === 'empty') { return ( Empty ); } const healthColor = getHealthColor(bed.health_score); const hasAlert = !!bed.last_alert; return ( <> {/* Main cell */} {/* Health score text */} {bed.health_score} {/* Alert indicator */} {hasAlert && ( )} {/* Batch ID (small text) */} {bed.plant_batch_id && ( {bed.plant_batch_id.substring(0, 8)} )} {/* Tooltip */} {showTooltip && bed && ( setShowTooltip(false)} /> )} ); }