import { Box, Card, Chip, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material' import { Trophy, CheckCircle2 } from 'lucide-react' import { LABEL_SX, DATA_SX, CRITERION_ALIASES, getTitle, scoreBar } from './compareUtils' import type { WeightingKey } from '../../domain/needBuilder' import { MissingDataCell } from './CompareCell' import type { UnifiedMatchResult } from '../../domain/unifiedResult' interface Props { compareItems: UnifiedMatchResult[] relevantCriteria: Array<{ key: string; label: string; weight: number }> overallWinnerIdx: number activeNeed: { companyName: string } } export function CompareCriteriaCard({ compareItems, relevantCriteria, overallWinnerIdx, activeNeed }: Props) { return ( Vergleich nach Suchkriterien Basierend auf der Suche: {activeNeed.companyName} {overallWinnerIdx !== -1 && ( Gesamtsieger {getTitle(compareItems[overallWinnerIdx])} )} Kriterium {compareItems.map(item => ( {getTitle(item)} ))} {relevantCriteria.map(({ key, label }) => { const allCriteria = (item: typeof compareItems[0]) => item.match.allFactors ?? [...item.match.positiveFactors, ...item.match.negativeFactors] const factors = compareItems.map(item => allCriteria(item).find(f => CRITERION_ALIASES[key as WeightingKey].some(a => a.toLowerCase() === f.criterion.toLowerCase())) ) const numericScores = factors.map(f => f?.score ?? null) const presentScores = numericScores.filter((s): s is number => s !== null) const maxScore = presentScores.length > 0 ? Math.max(...presentScores) : 0 const winnerIdx = compareItems.length > 1 && presentScores.length > 1 && numericScores.filter(s => s === maxScore).length === 1 ? numericScores.indexOf(maxScore) : -1 return ( {label} {factors.map((factor, idx) => ( {factor ? ( {scoreBar(factor.score / 100)} {idx === winnerIdx && ( } sx={{ height: 18, fontSize: 9, bgcolor: '#f0fdf4', color: '#166534', '& .MuiChip-icon': { color: '#1a7a4a', ml: 0.5 }, '& .MuiChip-label': { px: 0.75 } }} /> )} {factor.explanation} ) : ( )} ))} ) })}
) }