import React from 'react'; export interface ConditionBar { label: string; actual: number | null; standard: number | null; unit: string; /** Optional note shown under the bar, e.g. why a standard is absent. */ note?: string; } export interface InsightConditionChartProps { bars: ConditionBar[]; title?: string; emptyLabel?: string; } const AKTUAL = '#dc2626'; const STANDAR = '#3b82f6'; const fmt = (value: number, unit: string) => `${Number(value).toLocaleString('id-ID', { maximumFractionDigits: 1 })}${unit ? ` ${unit}` : ''}`; /** * Current readings against their CP 707 standard, one row per metric. * Used when there is no per-day history (e.g. live IoT snapshot). */ const InsightConditionChart: React.FC = ({ bars, title, emptyLabel = 'Belum ada pembacaan sensor untuk digambarkan.', }) => { const usable = bars.filter((bar) => bar.actual !== null || bar.standard !== null); if (usable.length === 0) { return (
{emptyLabel}
); } return (
{title &&

{title}

}
Aktual Standar CP 707
{usable.map((bar) => { const max = Math.max(bar.actual ?? 0, bar.standard ?? 0, 1); const pct = (value: number | null) => value === null ? 0 : Math.max(2, Math.round((value / max) * 100)); return (
{bar.label} {bar.actual === null ? 'data tidak tersedia' : fmt(bar.actual, bar.unit)} {bar.standard !== null && ( ยท standar {fmt(bar.standard, bar.unit)} )}
{bar.actual !== null && (
)}
{bar.standard !== null && (
)}
{bar.note &&

{bar.note}

}
); })}
); }; export default InsightConditionChart;