'use client'; import React from 'react'; import BusinessRuleLink from './BusinessRuleLink'; import { FiInfo } from 'react-icons/fi'; import { clampPercent, hexToRgba, scoreToColorHex } from '../colors'; type TopMover = { label?: string; uid?: string }; export default function RiskCard({ title, description, percentGood = 0, label, topMovers, topMoversTitle, tooltipText, }: { title: string; description?: string; percentGood?: number; label?: string; topMovers?: TopMover[]; topMoversTitle?: string; tooltipText?: string; }) { const pctGood = clampPercent(percentGood); const displayLabel = label || ''; // Background tint uses same thresholds as GaugeCard via scoreToColorHex // Foreground bar color uses same thresholds as GaugeCard based on overall score const activeColor = scoreToColorHex(pctGood); const headerTint = hexToRgba(scoreToColorHex(pctGood), 0.06); // bar heights ascending representation const bars = [40, 60, 85, 110, 140]; let activeIndex = 4; // Default to the highest bar (0% score) if (pctGood >= 80) { activeIndex = 0; } else if (pctGood >= 60) { activeIndex = 1; } else if (pctGood >= 40) { activeIndex = 2; } else if (pctGood >= 20) { activeIndex = 3; } return (
{title}
{description ? (
{description}
) : null}
{(tooltipText || description) && (
{title}
Score: {100 - pctGood}% (lower is better)
{tooltipText || description}
)}
{bars.map((h, i) => (
))} Low risk - - High Risk {(tooltipText || description) && (
{title}
Score: {100 - pctGood}% (lower is better)
{tooltipText || description}
)}
{displayLabel}
{Array.isArray(topMovers) && topMovers.length > 0 && (
{topMoversTitle || 'Top Score Movers'}
{topMovers.map((t, idx: number) => ( {idx < topMovers.length - 1 && |} ))}
)}
); }