function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
import { useId } from '@react-aria/utils';
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
  };
}
export function useNumberInputLabel(_ref2) {
  var ariaLabel = _ref2.ariaLabel,
    ariaLabelledBy = _ref2.ariaLabelledBy,
    id = _ref2.id,
    name = _ref2.name,
    prefix = _ref2.prefix,
    suffix = _ref2.suffix;
  var prefixDefaultId = useId();
  var suffixDefaultId = useId();
  var ariaLabelledByChained;
  var prefixId;
  var suffixId;
  if (prefix) {
    prefixId = id ? "".concat(id, "-prefix") : name ? "".concat(name, "-prefix") : prefixDefaultId;
  }
  if (suffix) {
    suffixId = id ? "".concat(id, "-suffix") : name ? "".concat(name, "-suffix") : suffixDefaultId;
  }
  if (ariaLabelledBy) {
    ariaLabelledByChained = prefixId || suffixId ? "".concat(ariaLabelledBy, " ").concat(prefixId || suffixId) : ariaLabelledBy;
  }
  if (ariaLabel) {
    ariaLabelledByChained = prefixId || suffixId ? "".concat(id, " ").concat(prefixId || suffixId) : id;
  }
  return {
    inputProps: {
      'aria-label': ariaLabel,
      'aria-labelledby': ariaLabelledByChained
    },
    prefixProps: {
      'aria-hidden': !ariaLabel,
      id: prefixId
    },
    suffixProps: {
      'aria-hidden': !ariaLabel,
      id: suffixId
    }
  };
}
//# sourceMappingURL=NumberInput.hooks.js.map