/**
 * Format a monetary amount with its currency symbol.
 * Client-safe: works in both server and client components.
 * @param amount - The numeric amount to format
 * @param symbol - The currency symbol to append (e.g. '$', 'ل.س', '€')
 * @param decimalPlaces - Number of decimal places (default: 2)
 * @returns Formatted string such as "1,234.56 $" or "1,234.56 ل.س"
 */
export function formatCurrency(amount: number, symbol: string = '', decimalPlaces: number = 2): string {
  const numericAmount = Number(amount ?? 0);
  const safeAmount = Number.isFinite(numericAmount) ? numericAmount : 0;
  const formatted = safeAmount.toFixed(decimalPlaces);
  return symbol ? `${formatted} ${symbol}` : formatted;
}

/**
 * Format amount without currency symbol
 * @param amount - The numeric amount to format
 * @param decimalPlaces - Number of decimal places (default: 2)
 * @returns Formatted string without currency symbol
 */
export function formatAmount(amount: number, decimalPlaces: number = 2): string {
  const numericAmount = Number(amount ?? 0);
  const safeAmount = Number.isFinite(numericAmount) ? numericAmount : 0;
  return safeAmount.toFixed(decimalPlaces);
}
