import { Card, Group, Progress, SimpleGrid, Text, Tooltip } from "@mantine/core"; import { useTranslation } from "react-i18next"; import { localized } from "@/shared/lib/localizedName"; import type { LeaveBalance } from "../types"; /** * Balances at a glance. * * The bar shows what has been used against what was granted, because "11 of 16" * answers the question faster than "11". Types with nothing granted are still * shown — an employee who is not yet eligible needs to see that the leave exists * and is at zero, not have it hidden and wonder whether the system knows about it. */ export function BalanceCards({ balances, onOpen, }: { balances: LeaveBalance[]; onOpen?: (balance: LeaveBalance) => void; }) { const { i18n } = useTranslation(); return ( {balances.map((balance) => { const used = balance.grantedDays > 0 ? (balance.takenDays / balance.grantedDays) * 100 : 0; const low = balance.grantedDays > 0 && balance.availableDays <= 0; return ( onOpen?.(balance)} >
{localized(balance.name, i18n.language) || balance.code} {balance.leaveYearStart} — {balance.leaveYearEnd}
{balance.availableDays}
{balance.takenDays} taken of {balance.grantedDays} {balance.adjustmentDays !== 0 && ( {balance.adjustmentDays > 0 ? "+" : ""} {balance.adjustmentDays} adjusted )} {balance.carriedOverDays > 0 && ( includes {balance.carriedOverDays} carried over {balance.carryOverExpiresOn ? `, lapsing ${balance.carryOverExpiresOn}` : ""} )}
); })}
); }