import { useMemo } from 'react';
import { useCurrency } from '../contexts/CurrencyContext';
import { formatCurrency as formatCurrencyUtil } from '../../../shared/utils/format';

export const useFormatCurrency = () => {
  const { currency } = useCurrency();

  const formatCurrency = useMemo(
    () => (amount: number | string, overrideCurrency?: string) => {
      return formatCurrencyUtil(amount, overrideCurrency || currency);
    },
    [currency]
  );

  return { formatCurrency, currency };
};

