import { formatNumber } from '@pisell/utils';

/**
 * 货币格式化选项
 */

/**
 * 格式化货币数值
 * 
 * @param value 数值
 * @param options 格式化选项
 * @returns 格式化后的货币字符串
 * 
 * @example
 * formatCurrency(1234.56, { currencySymbol: '¥', symbolPosition: 'before', showSymbol: true, precision: 2, useGrouping: true })
 * // 返回: '¥1,234.56'
 * 
 * @example
 * formatCurrency(999.99, { currencySymbol: '€', symbolPosition: 'after', showSymbol: true, precision: 2, useGrouping: true })
 * // 返回: '999.99€'
 */
export function formatCurrency(value, options) {
  if (value === null || value === undefined) {
    return null;
  }
  var currencySymbol = options.currencySymbol,
    symbolPosition = options.symbolPosition,
    showSymbol = options.showSymbol,
    precision = options.precision,
    useGrouping = options.useGrouping;

  // 1. 基础数值格式化（千分位 + 精度）
  var formatted = formatNumber(value, {
    precision: precision,
    useGrouping: useGrouping
  });
  if (!formatted) {
    return null;
  }

  // 2. 添加货币符号（符号与数值之间无空格）
  if (!showSymbol) {
    return formatted;
  }
  if (symbolPosition === 'before') {
    return "".concat(currencySymbol).concat(formatted);
  } else {
    return "".concat(formatted).concat(currencySymbol);
  }
}