/** Currency code carried on invoices / dashboard figures (ETB, USD, DJF, …). */
export type Currency = string;

const SYMBOLS: Record<string, string> = {
  USD: "$",
  ETB: "Br",
  DJF: "DJF",
};

/**
 * Format a money amount with its currency symbol, e.g. `Br 12,500.00`.
 * Unknown currency codes fall back to printing the raw code.
 */
export function formatCurrency(
  amount: number,
  currency: Currency = "ETB",
): string {
  const symbol = SYMBOLS[currency] ?? currency;
  return `${symbol} ${Number(amount ?? 0).toLocaleString(undefined, {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
  })}`;
}
