function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React from 'react';
import { defaultLocale, format, getLengthInfo, verifyDecimalScale } from './NumberInput.utils';
export function usePrevious(value) {
  var ref = React.useRef();
  React.useEffect(function () {
    ref.current = value;
  });
  return ref.current;
}
export function useNumberFormat(_ref) {
  var _ref$decimalScale = _ref.decimalScale,
    _decimalScale = _ref$decimalScale === void 0 ? true : _ref$decimalScale,
    _ref$fillDecimalScale = _ref.fillDecimalScale,
    fillDecimalScale = _ref$fillDecimalScale === void 0 ? 'none' : _ref$fillDecimalScale,
    _ref$locale = _ref.locale,
    _locale = _ref$locale === void 0 ? defaultLocale : _ref$locale;
  var locale = React.useMemo(function () {
    return [].concat(_toConsumableArray(Array.isArray(_locale) ? _locale : [_locale]), [defaultLocale]);
  }, [_locale]);
  var _React$useMemo = React.useMemo(function () {
      return {
        fixedDecimalScale: fillDecimalScale === 'always',
        fillDecimalScaleOnBlur: fillDecimalScale === 'onBlur'
      };
    }, [fillDecimalScale]),
    fixedDecimalScale = _React$useMemo.fixedDecimalScale,
    fillDecimalScaleOnBlur = _React$useMemo.fillDecimalScaleOnBlur;
  var decimalScale = React.useMemo(function () {
    return verifyDecimalScale(_decimalScale);
  }, [_decimalScale]);
  var formatValue = React.useCallback(function (value) {
    return format(locale, decimalScale, fillDecimalScale, value);
  }, [locale, decimalScale, fillDecimalScale]);
  var getValueLengthInfo = React.useCallback(function (value) {
    var isNumericString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    return getLengthInfo(locale, value, decimalScale, fillDecimalScale, isNumericString);
  }, [locale, decimalScale, fillDecimalScale]);
  return {
    formatValue: formatValue,
    getValueLengthInfo: getValueLengthInfo,
    locale: locale,
    fixedDecimalScale: fixedDecimalScale,
    fillDecimalScaleOnBlur: fillDecimalScaleOnBlur,
    decimalScale: decimalScale
  };
}
//# sourceMappingURL=NumberInput.hooks.js.map