import React from 'react'; import { SENSOR_ICON_HUMIDITY, SENSOR_ICON_WATER, baseCard, sensorCard } from './constants.tsx'; import IotPanelExperienceTempCard from './IotPanelExperienceTempCard.tsx'; import type { IotComputedDashboard, IotHistoryMetric } from './types.ts'; type SensorTile = | { iconEmoji: string; label: string; value: string; historyMetric?: IotHistoryMetric } | { iconClass: string; label: string; value: string; historyMetric?: IotHistoryMetric } | { iconText: string; label: string; value: string; historyMetric?: IotHistoryMetric }; export interface IotPanelEnvironmentColumnProps { computed: IotComputedDashboard; onSensorHistoryClick?: (metric: IotHistoryMetric) => void; sensorHistoryLoading?: boolean; } const IotPanelEnvironmentColumn: React.FC = ({ computed, onSensorHistoryClick, sensorHistoryLoading = false, }) => { const sensorTiles: SensorTile[] = [ { iconEmoji: SENSOR_ICON_HUMIDITY, label: 'Kelembapan', value: computed.humidity, historyMetric: 'humidity', }, { iconClass: 'fa-solid fa-temperature-quarter text-orange-500', label: 'Suhu Luar', value: computed.outsideTemp, historyMetric: 'outsideTemp', }, { iconClass: 'fa-solid fa-dove text-amber-600', label: 'Umur Ayam', value: computed.dayAge }, { iconText: 'NH3', label: 'NH3', value: computed.ammonia, historyMetric: 'ammonia' }, { iconText: 'CO2', label: 'CO2', value: computed.co2, historyMetric: 'co2' }, { iconEmoji: SENSOR_ICON_WATER, label: 'Air', value: computed.water, historyMetric: 'water' }, { iconClass: 'fa-solid fa-wind text-indigo-600', label: 'Angin', value: computed.wind, historyMetric: 'wind', }, { iconClass: 'fa-solid fa-sun text-yellow-500', label: 'Lux', value: computed.lux, historyMetric: 'lux', }, ]; const tempCells: { label: string; value: string; metric: IotHistoryMetric; alarmHighlight: boolean; }[] = [ { label: '1', value: computed.temp1, metric: 'temp1', alarmHighlight: computed.temp1AlarmHighlight, }, { label: '2', value: computed.temp2, metric: 'temp2', alarmHighlight: computed.temp2AlarmHighlight, }, { label: '3', value: computed.temp3, metric: 'temp3', alarmHighlight: computed.temp3AlarmHighlight, }, ]; const tempValueClass = (alarmHighlight: boolean) => `text-2xl font-semibold ${alarmHighlight ? 'text-red-600' : ''}`; const avgTempValueClass = computed.avgTempAlarmHighlight ? 'mt-2 text-3xl font-bold text-red-600' : 'mt-2 text-3xl font-bold text-slate-700'; return (
{onSensorHistoryClick ? ( ) : (

Suhu Set Point

{computed.setPoint}

)}
{tempCells.map((item) => onSensorHistoryClick ? ( ) : (

{item.label}

{item.value}

) )}
{sensorTiles.map((item, idx) => { const metric = item.historyMetric; const clickable = Boolean(metric && onSensorHistoryClick); const inner = ( <>

{'iconEmoji' in item && item.iconEmoji ? ( ) : 'iconText' in item && item.iconText ? ( {item.iconText} ) : ( )}

{item.value}

); if (!clickable) { return (
{inner}
); } return ( ); })}
); }; export default IotPanelEnvironmentColumn;