/**
 * Formats a number as currency with the appropriate symbol
 * @param amount - The amount to format
 * @param currency - The currency code (e.g., 'USD', 'TTD', 'EUR')
 * @returns Formatted currency string
 */
export function formatCurrency(amount: number, currency = "USD"): string {
  // Map of currency codes to their symbols and formatting
  const currencyConfig: Record<string, { symbol: string; position: "before" | "after" }> = {
    USD: { symbol: "$", position: "before" },
    TTD: { symbol: "TTD", position: "before" },
    EUR: { symbol: "€", position: "before" },
    GBP: { symbol: "£", position: "before" },
    CAD: { symbol: "CA$", position: "before" },
    AUD: { symbol: "A$", position: "before" },
    JMD: { symbol: "J$", position: "before" },
    BBD: { symbol: "Bds$", position: "before" },
    XCD: { symbol: "EC$", position: "before" },
    BSD: { symbol: "B$", position: "before" },
  }

  const config = currencyConfig[currency.toUpperCase()] || { symbol: currency, position: "before" }

  // Format the number with 2 decimal places and thousand separators
  const formattedAmount = amount.toLocaleString("en-US", {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
  })

  if (config.position === "before") {
    return `${config.symbol} ${formattedAmount}`
  } else {
    return `${formattedAmount} ${config.symbol}`
  }
}
