import { useState, useEffect } from 'react' import { budgetApi } from '../../api/client' import type { BudgetItem } from '../../types' import { fmtNum, colorForUserId, widgetTheme } from './BudgetPanel.helpers' import RingAvatar from './BudgetPanelRingAvatar' interface PerPersonSummaryEntry { user_id: number username: string avatar_url: string | null total_assigned: number } interface PerPersonInlineProps { tripId: number budgetItems: BudgetItem[] currency: string locale: string } export default function PerPersonInline({ tripId, budgetItems, currency, locale, grandTotal, theme }: PerPersonInlineProps & { grandTotal: number; theme: ReturnType }) { const [data, setData] = useState(null) const fmt = (v: number) => fmtNum(v, locale, currency) useEffect(() => { budgetApi.perPersonSummary(tripId).then(d => setData(d.summary)).catch(() => {}) }, [tripId, budgetItems]) if (!data || data.length === 0) return null const people = data.map(p => ({ ...p, color: colorForUserId(p.user_id) })) return ( <> {grandTotal > 0 && (
{people.map(p => (
))}
)}
{people.map(p => { const percent = grandTotal > 0 ? Math.round((p.total_assigned / grandTotal) * 100) : 0 return (
{p.username}
{percent}%
{fmt(p.total_assigned)}
) })}
) }