import React from 'react';
import { DimensionAnalysis } from '../types';
import { motion } from 'framer-motion';
import { AlertCircle, AlertTriangle, TrendingUp, CheckCircle, Zap } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import BadgePill from './BadgePill';
interface HealthStatus {
level: 'critical' | 'low' | 'medium' | 'good' | 'excellent';
label: string;
color: string;
textColor: string;
bgColor: string;
icon: React.ReactNode;
description: string;
}
const getHealthStatus = (score: number, t: (key: string) => string): HealthStatus => {
if (score >= 86) {
return {
level: 'excellent',
label: t('healthStatus.excellent'),
color: 'text-cyan-700',
textColor: 'text-cyan-700',
bgColor: 'bg-cyan-50',
icon: ,
description: t('healthStatus.excellentDesc')
};
}
if (score >= 71) {
return {
level: 'good',
label: t('healthStatus.good'),
color: 'text-emerald-700',
textColor: 'text-emerald-700',
bgColor: 'bg-emerald-50',
icon: ,
description: t('healthStatus.goodDesc')
};
}
if (score >= 51) {
return {
level: 'medium',
label: t('healthStatus.medium'),
color: 'text-amber-700',
textColor: 'text-amber-700',
bgColor: 'bg-amber-50',
icon: ,
description: t('healthStatus.mediumDesc')
};
}
if (score >= 31) {
return {
level: 'low',
label: t('healthStatus.low'),
color: 'text-orange-700',
textColor: 'text-orange-700',
bgColor: 'bg-orange-50',
icon: ,
description: t('healthStatus.lowDesc')
};
}
return {
level: 'critical',
label: t('healthStatus.critical'),
color: 'text-red-700',
textColor: 'text-red-700',
bgColor: 'bg-red-50',
icon: ,
description: t('healthStatus.criticalDesc')
};
};
const getProgressBarColor = (score: number): string => {
if (score >= 86) return 'bg-cyan-500';
if (score >= 71) return 'bg-emerald-500';
if (score >= 51) return 'bg-amber-500';
if (score >= 31) return 'bg-orange-500';
return 'bg-red-500';
};
const ScoreIndicator: React.FC<{ score: number; benchmark?: number }> = ({ score, benchmark }) => {
const { t } = useTranslation();
const healthStatus = getHealthStatus(score, t);
return (
{/* Main Score Display */}
{/* Progress Bar with Scale Reference */}
{/* Scale Reference */}
0
25
50
75
100
{/* Benchmark Comparison */}
{benchmark !== undefined && (
{t('benchmark.title')}
{benchmark}/100
{score > benchmark ? (
{t('benchmark.aboveBenchmark', { points: score - benchmark })}
) : score === benchmark ? (
{t('benchmark.atBenchmark')}
) : (
{t('benchmark.belowBenchmark', { points: benchmark - score })}
)}
)}
{/* Health Status Description */}
{healthStatus.icon}
{healthStatus.description}
);
};
const DimensionCard: React.FC<{ dimension: DimensionAnalysis }> = ({ dimension }) => {
const { t } = useTranslation();
const healthStatus = getHealthStatus(dimension.score, t);
return (
{/* Header */}
{dimension.title}
{dimension.name}
{dimension.score >= 86 && (
⭐
)}
{/* Score Indicator */}
{/* Summary Description */}
{dimension.summary}
{/* KPI Display */}
{dimension.kpi && (
{dimension.kpi.label}
{dimension.kpi.value}
{dimension.kpi.change && (
{dimension.kpi.change}
)}
)}
{/* Action Button */}
= 71}
>
{dimension.score < 51
? t('dimensionCard.viewCriticalActions')
: dimension.score < 71
? t('dimensionCard.exploreImprovements')
: t('dimensionCard.inGoodState')}
);
};
export default DimensionCard;