/**
 * Currency Utilities
 * Single currency system - all amounts use ZEN_CURRENCY from .env
 */

import { getAppConfig } from '../lib/appConfig.js';

/**
 * Get default currency from configuration
 * @returns {string} Currency code (e.g., 'CAD')
 */
export function getDefaultCurrency() {
  const config = getAppConfig();
  return config.defaultCurrency;
}

/**
 * Get currency symbol from configuration
 * @returns {string} Currency symbol (e.g., '$')
 */
export function getCurrencySymbol() {
  const config = getAppConfig();
  return config.currencySymbol;
}

/**
 * Format amount with currency symbol
 * @param {number} amount - Amount to format
 * @returns {string} Formatted currency string (e.g., "$1,234.56")
 */
export function formatCurrency(amount) {
  const currencyCode = getDefaultCurrency();
  const symbol = getCurrencySymbol();
  
  try {
    return new Intl.NumberFormat('en-CA', {
      style: 'currency',
      currency: currencyCode,
    }).format(amount);
  } catch (error) {
    // Fallback if Intl fails
    return `${symbol}${amount.toFixed(2)}`;
  }
}

