import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Progress } from '@/components/ui/progress'; import { Link } from 'react-router-dom'; import { ExternalLink } from 'lucide-react'; interface Column { key: string; label: string; numeric?: boolean; linkBase?: string; } interface ComparisonTableProps { title: string; data: any[]; columns: Column[]; slugKey: string; parkSlugKey?: string; } export function ComparisonTable({ title, data, columns, slugKey, parkSlugKey }: ComparisonTableProps) { if (!data || data.length === 0) { return (
No data available
); } // Find the max value for each numeric column (for progress bars) const maxValues: Record = {}; columns.forEach(col => { if (col.numeric) { maxValues[col.key] = Math.max(...data.map(row => row[col.key] || 0)); } }); return (

{title}

Rank {columns.map(col => ( {col.label} ))} {data.map((row, index) => { const slug = row[slugKey]; const parkSlug = parkSlugKey ? row[parkSlugKey] : null; return ( #{index + 1} {columns.map(col => { const value = row[col.key]; const isFirst = col === columns[0]; if (isFirst && col.linkBase && slug) { const linkPath = parkSlug ? `${col.linkBase}/${parkSlug}/rides/${slug}` : `${col.linkBase}/${slug}`; return ( {value} ); } if (col.numeric) { const percentage = (value / maxValues[col.key]) * 100; return (
{value}
); } return {value}; })}
); })}
); }