/**
 * Safely format a numeric value as Brazilian currency (R$)
 * Handles undefined, null, and NaN values gracefully
 */
export const formatCurrency = (value: number | undefined | null): string => {
    if (value === undefined || value === null || isNaN(value)) {
        return '0,00'
    }
    return value.toFixed(2).replace('.', ',')
}

/**
 * Format cents to currency string
 */
export const formatCents = (cents: number | undefined | null): string => {
    if (cents === undefined || cents === null || isNaN(cents)) {
        return 'R$ 0,00'
    }
    return `R$ ${(cents / 100).toFixed(2).replace('.', ',')}`
}
