import _extends from "@babel/runtime/helpers/esm/extends";
var defaultConfig = {
  currencySymbol: '',
  groupSeparator: '',
  decimalSeparator: '',
  prefix: '',
  suffix: ''
};

/**
 * Get locale config from input or default
 */
export var getLocaleConfig = function getLocaleConfig(intlConfig) {
  var _ref = intlConfig || {},
    locale = _ref.locale,
    currency = _ref.currency;
  var numberFormatter = locale ? new Intl.NumberFormat(locale, currency ? {
    currency: currency,
    style: 'currency'
  } : undefined) : new Intl.NumberFormat();
  return numberFormatter.formatToParts(1000.1).reduce(function (prev, curr, i) {
    if (curr.type === 'currency') {
      if (i === 0) {
        return _extends({}, prev, {
          currencySymbol: curr.value,
          prefix: curr.value
        });
      } else {
        return _extends({}, prev, {
          currencySymbol: curr.value,
          suffix: curr.value
        });
      }
    }
    if (curr.type === 'group') {
      return _extends({}, prev, {
        groupSeparator: curr.value
      });
    }
    if (curr.type === 'decimal') {
      return _extends({}, prev, {
        decimalSeparator: curr.value
      });
    }
    return prev;
  }, defaultConfig);
};