import { Balances } from '@/lib/balances' import { cn } from '@/lib/utils' import { Participant } from '@prisma/client' type Props = { balances: Balances participants: Participant[] currency: string } export function BalancesList({ balances, participants, currency }: Props) { const maxBalance = Math.max( ...Object.values(balances).map((b) => Math.abs(b.total)), ) return (
{participants.map((participant) => (
= 0 || 'flex-row-reverse', )} >
= 0 && 'text-right', )} > {participant.name}
= 0 || 'text-right', )} >
{currency} {(balances[participant.id]?.total ?? 0).toFixed(2)}
{balances[participant.id]?.total !== 0 && (
0 ? 'bg-green-200 left-0 rounded-r-lg border border-green-300' : 'bg-red-200 right-0 rounded-l-lg border border-red-300', )} style={{ width: (Math.abs(balances[participant.id]?.total ?? 0) / maxBalance) * 100 + '%', }} >
)}
))}
) }