'use client'; import { getRating as getCoreRating } from '@aiready/core/client'; import { cn } from '../utils/cn'; export type ScoreRating = | 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical'; export interface ScoreBarProps { score: number; maxScore?: number; label: string; showScore?: boolean; size?: 'sm' | 'md' | 'lg'; className?: string; } const ratingConfig: Record< ScoreRating, { color: string; bgColor: string; label: string } > = { excellent: { color: 'bg-green-500', bgColor: 'bg-green-100', label: 'Excellent', }, good: { color: 'bg-emerald-500', bgColor: 'bg-emerald-100', label: 'Good' }, fair: { color: 'bg-amber-500', bgColor: 'bg-amber-100', label: 'Fair' }, 'needs-work': { color: 'bg-orange-500', bgColor: 'bg-orange-100', label: 'Needs Work', }, critical: { color: 'bg-red-500', bgColor: 'bg-red-100', label: 'Critical' }, }; // Convert Title Case rating from core to lowercase for component use function getRating(score: number): ScoreRating { const coreRating = getCoreRating(score); const ratingMap: Record = { Excellent: 'excellent', Good: 'good', Fair: 'fair', 'Needs Work': 'needs-work', Critical: 'critical', }; return ratingMap[coreRating] || 'critical'; } const sizeConfig = { sm: { height: 'h-1.5', text: 'text-xs', score: 'text-sm' }, md: { height: 'h-2', text: 'text-sm', score: 'text-base' }, lg: { height: 'h-3', text: 'text-base', score: 'text-lg' }, }; export function ScoreBar({ score, maxScore = 100, label, showScore = true, size = 'md', className, }: ScoreBarProps) { const percentage = Math.min(100, Math.max(0, (score / maxScore) * 100)); const rating = getRating(percentage); const config = ratingConfig[rating]; const sizes = sizeConfig[size]; return (
{label} {showScore && ( {score}/{maxScore} )}
); } export interface ScoreCardProps { score: number; title?: string; breakdown?: Array<{ label: string; score: number; weight?: number; }>; className?: string; } export function ScoreCard({ score, title, breakdown, className, }: ScoreCardProps) { const rating = getRating(score); const config = ratingConfig[rating]; return (
{score}/100
{config.label} Rating
{title &&

{title}

}
{breakdown && breakdown.length > 0 && (
{breakdown.map((item, index) => ( ))}
)} {breakdown && breakdown.length > 0 && (
Formula:{' '} {breakdown .map((item) => `${item.score}×${item.weight || 1}`) .join(' + ')}{' '} / 100 = {score}
)}
); }