'use client'; import React, { useMemo } from 'react'; import GaugeComponent from '@knowyourdeveloper/react-gauge-component'; import BusinessRuleLink from './BusinessRuleLink'; import { FiInfo } from 'react-icons/fi'; import { hexToRgba, scoreToColorHex, clampPercent, red, yellow, green, green1, green2, green3, green4, green5 } from '../colors'; type TopMover = { label?: string; uid?: string }; // color helpers moved to ../utils/color export default function GaugeCard({ title, description, percent = 0, label, topMovers, topMoversTitle, tooltipText, selfCheck, }: { title: string; description?: string; percent?: number; label?: string; topMovers?: TopMover[]; topMoversTitle?: string; tooltipText?: string; selfCheck?: boolean; }) { const pct = clampPercent(percent); const displayLabel = label || ''; const shadeFor = (p: number) => { if (p < 20) return green5; if (p < 40) return green4; if (p < 60) return green3; if (p < 80) return green2; return green1; }; const headerTint = hexToRgba(selfCheck ? shadeFor(pct) : scoreToColorHex(pct), 0.06); // Technical evidence tiers from backend thresholds const tickLabels = useMemo(() => ({ type: 'outer' as const, hideMinMax: true, defaultTickLineConfig: { length: 7, width: 1, distanceFromArc: 3, color: 'var(--icon-button-secondary)' }, defaultTickValueConfig: { style: { fontSize: '10px', fill: 'var(--text-secondary)' } }, ticks: [ { value: 16, valueConfig: { formatTextValue: () => 'Low' } }, { value: 50, valueConfig: { formatTextValue: () => 'Moderate' } }, { value: 83, valueConfig: { formatTextValue: () => 'High' } }, ] }), []); return (
{title}
{description}
{(tooltipText || description) && (
{title}
Score: {pct}%
{tooltipText || description}
)}
displayLabel, matchColorWithArc: true, style: { textShadow: 'none' } }, tickLabels: tickLabels, }} arc={{ padding: 0.02, subArcs: selfCheck ? [ { limit: 20, color: green5 }, { limit: 40, color: green4 }, { limit: 60, color: green3 }, { limit: 80, color: green2 }, { limit: 100, color: green1 }, ] : [ { limit: 33, color: red }, { limit: 66, color: yellow }, { limit: 100, color: green }, ], }} pointer={{ type: 'blob', elastic: true, animationDelay: 0 }} /> {(tooltipText || description) && (
{title}
Score: {pct}%
{tooltipText || description}
)}
{Array.isArray(topMovers) && topMovers.length > 0 && (
{topMoversTitle || 'Top Score Movers'}
{topMovers.map((t, idx: number) => ( {idx < topMovers.length - 1 && |} ))}
)}
); }