import { useEffect, useRef } from 'react'; import { Bed } from './GrowRoomHeatmap'; /** * BedTooltip - Hover tooltip showing bed details * * Displays key information about a bed when hovering over it. * Positioned near the mouse cursor. */ interface BedTooltipProps { bed: Bed; position: { x: number; y: number }; onClose: () => void; } export default function BedTooltip({ bed, position, onClose }: BedTooltipProps) { const tooltipRef = useRef(null); // Close on click outside useEffect(() => { function handleClickOutside(event: MouseEvent) { if (tooltipRef.current && !tooltipRef.current.contains(event.target as Node)) { onClose(); } } document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, [onClose]); const getHealthLabel = (score: number): string => { if (score >= 90) return 'Excellent'; if (score >= 70) return 'Good'; if (score >= 50) return 'Fair'; if (score >= 30) return 'Needs Attention'; return 'Critical'; }; const getHealthColor = (score: number): string => { if (score >= 90) return 'text-[var(--color-primary)] dark:text-emerald-400'; if (score >= 70) return 'text-[var(--color-primary)] dark:text-emerald-300'; if (score >= 50) return 'text-yellow-500 dark:text-yellow-300'; if (score >= 30) return 'text-orange-500 dark:text-orange-300'; return 'text-red-600 dark:text-red-400'; }; return (
{/* Header */}
Bed {bed.bed_id}
{bed.plant_batch_id && (
Batch: {bed.plant_batch_id}
)}
{/* Health Score */}
Health Score {bed.health_score}
{getHealthLabel(bed.health_score)}
{/* Sensors */} {bed.sensors && (
Sensor Readings
{bed.sensors.temp !== undefined && ( )} {bed.sensors.humidity !== undefined && ( )} {bed.sensors.ec !== undefined && ( )} {bed.sensors.par !== undefined && ( )}
)} {/* Last Alert */} {bed.last_alert && (
⚠️ Last Alert: {bed.last_alert}
)} {/* Actions */}
); } function SensorReading({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); }