import type { ReactNode } from 'react'; import { fmt, fmtDelta } from '@/lib/format'; import { levelById, levelFor, pressureColor, trendArrow, type LEVELS } from '@/lib/pressure'; import type { LevelId, Trend } from '@/lib/types'; export function Section({ id, label, title, right, children, className = '' }: { id?: string; label?: string; title?: string; right?: ReactNode; children: ReactNode; className?: string }) { return (
{(label || title || right) && (
{label && {label}} {title &&

{title}

}
{right &&
{right}
}
)} {children}
); } export function LevelBadge({ level, value, size = 'sm' }: { level?: LevelId | string | null; value?: number | null; size?: 'xs' | 'sm' | 'md' }) { const l = level ? levelById(level) : value != null ? levelFor(value) : undefined; const color = l?.color ?? '#3A4756'; const cls = size === 'xs' ? 'text-[10px] tracking-[0.1em]' : size === 'md' ? 'text-[13px] tracking-[0.12em]' : 'text-[11px] tracking-[0.12em]'; return ( ); } /** Pressure numeral coloured by level. */ export function PNum({ value, digits = 1, className = '' }: { value: number | null | undefined; digits?: number; className?: string }) { return ( {fmt(value, digits)} ); } /** Signed delta with arrow; rising pressure is warm, falling is cool. */ export function Delta({ value, trend, digits = 1, suffix, className = '' }: { value: number | null | undefined; trend?: Trend; digits?: number; suffix?: string; className?: string }) { if (value == null) return —; const arrow = trendArrow(trend, value); const color = value > 0.05 ? 'var(--p-stressed)' : value < -0.05 ? 'var(--p-calm)' : 'var(--ink-2)'; return ( {arrow} {fmtDelta(value, digits)} {suffix ? {suffix} : null} ); } /** Thin horizontal bar 0–100 coloured by pressure (or a fixed colour). */ export function Bar({ value, max = 100, color, height = 3, className = '' }: { value: number | null | undefined; max?: number; color?: string; height?: number; className?: string }) { const v = value == null ? 0 : Math.max(0, Math.min(max, value)); return (