import React from 'react'; /** * Headline figures for the dashboard AI Insight card. * * Replaces a nine-row label/value list in which every number wore the same * weight, so nothing led the eye. A handful of headline numbers is a KPI row of * stat tiles, not a list — one hero figure carries the metric the card is * really about and the tiles support it. */ export type InsightStatus = 'ok' | 'warning' | 'critical' | 'unknown'; /** * Status is never carried by hue alone: every chip pairs a glyph and a word * with its color, and the text tone (not the fill) is what clears contrast. */ const STATUS_CHIP: Record = { ok: { cls: 'bg-green-50 text-green-800 border-green-200', glyph: '✓' }, warning: { cls: 'bg-amber-50 text-amber-800 border-amber-200', glyph: '!' }, critical: { cls: 'bg-red-50 text-red-800 border-red-200', glyph: '⚠' }, unknown: { cls: 'bg-gray-50 text-gray-500 border-gray-200', glyph: '–' }, }; interface DeltaChipProps { status: InsightStatus; label: string; } export const DeltaChip: React.FC = ({ status, label }) => { const chip = STATUS_CHIP[status]; return ( {label} ); }; /** * A 40px trend line. Deliberately axis-less and label-less: it conveys shape * only, and the tile's number carries the value. Drawn as a plain polyline so * the card gains no chart dependency for something this small. */ export const Sparkline: React.FC<{ values: number[]; className?: string }> = ({ values, className, }) => { const clean = values.filter((v) => typeof v === 'number' && Number.isFinite(v)); if (clean.length < 2) return null; const width = 88; const height = 28; const min = Math.min(...clean); const max = Math.max(...clean); const span = max - min || 1; const step = width / (clean.length - 1); const points = clean .map((value, index) => { const x = index * step; // 2px inset top and bottom so the stroke is never clipped by the box. const y = height - 2 - ((value - min) / span) * (height - 4); return `${x.toFixed(1)},${y.toFixed(1)}`; }) .join(' '); return ( ); }; interface HeroFigureProps { label: string; value: string; unit?: string; /** e.g. "Standar CP 707 hari ke-48: 1,60" */ context?: string | null; status?: InsightStatus; deltaLabel?: string | null; sparkline?: number[]; } export const HeroFigure: React.FC = ({ label, value, unit, context, status = 'unknown', deltaLabel, sparkline, }) => (
{label}
{/* `leading-none` makes the line box exactly the font size, which is fine in a browser but clips ascenders and descenders under html2canvas — the PDF cut the top off every hero number. A little leading costs nothing on screen and fixes the export. */} {value} {unit ? {unit} : null}
{deltaLabel ? : null} {context ? {context} : null}
{sparkline && sparkline.length > 1 ? ( ) : null}
); interface StatTileProps { label: string; value: string; unit?: string; /** Small grey qualifier under the label, e.g. the period. */ hint?: string | null; status?: InsightStatus; deltaLabel?: string | null; sparkline?: number[]; } export const StatTile: React.FC = ({ label, value, unit, hint, status = 'unknown', deltaLabel, sparkline, }) => (
{label} {hint ? {hint} : null}
{/* Same reason as the hero above. */} {value} {unit ? {unit} : null}
{deltaLabel ? (
) : null} {sparkline && sparkline.length > 1 ? ( ) : null}
); /** Secondary figures: still present, but visibly subordinate to the tiles. */ export const MutedStatRow: React.FC<{ label: string; hint?: string | null; value: string }> = ({ label, hint, value, }) => (
{label} {hint ? {hint} : null} {value}
);