import { cn } from '@/lib/utils'; // MeterBar is the ONE LED-bar meter used across the FlexRadio panel, the amplifier // cards and the Tuner Genius card, so every meter renders at exactly the same size // (segment count, bar height, padding). Keep it the single source of truth — don't // re-declare a local copy in a panel, or the meters drift out of sync. export const METER_SEGMENTS = 26; export function MeterBar({ label, value, unit, lo, hi, accent = '#16a34a', extra, display, segColor, onClick, title, compact }: { label: string; value: number; unit?: string; lo: number; hi: number; accent?: string; extra?: string; display?: string; segColor?: (frac: number) => string; onClick?: () => void; title?: string; compact?: boolean; }) { const span = hi - lo; const pct = span > 0 ? Math.max(0, Math.min(100, ((value - lo) / span) * 100)) : 0; const lit = Math.round((pct / 100) * METER_SEGMENTS); return (
{label} {display !== undefined ? display : ( <>{Math.abs(value) >= 100 ? value.toFixed(0) : value.toFixed(1)}{unit} )}
{/* LED bar — recessed track + gradient segments for a cleaner instrument look. */}
{Array.from({ length: METER_SEGMENTS }).map((_, i) => { const on = i < lit; const frac = i / METER_SEGMENTS; const col = segColor ? segColor(frac) : (frac > 0.82 ? '#dc2626' : accent); return (
); })}
{extra && !compact &&
{extra}
}
); }