function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["decimalScale", "defaultValue", "disabled", "error", "fillDecimalScale", "locale", "onChange", "onKeyDown", "onBlur", "prefix", "readOnly", "step", "style", "suffix", "value", "qa"],
  _excluded2 = ["currencyDisplay", "currencyIsoCode", "decimalScale", "fillDecimalScale", "prefix", "suffix"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { formatCurrencyToParts } from '@procore/globalization-toolkit';
import { findIndex } from 'ramda';
import React from 'react';
import { useI18nContext } from '../_hooks/I18n';
import { spacing } from '../_styles/spacing';
import { mergeRefs } from '../_utils/mergeRefs';
import { defaultCurrencyFillDecimalScale, defaultCurrencyInputPrefix } from './NumberInput.constants';
import { useNumberFormat, usePrevious } from './NumberInput.hooks';
import { addonRootFontFamily, addonRootFontSize, addonRootPadding, inputDefaultXPadding, StyledIncrementerButton, StyledIncrementerWrapper, StyledInput, StyledPrefix, StyledSuffix, StyledWrapper } from './NumberInput.styles';
import { backspaceKey, commaKey, controlKey, copyKey, defaultLocale, deleteKey, emptyString, format, getNewCursorPosition, getSeparators, highlightAllKey, identicalLocales, identifyPressedKey, maxDigitLength, metaKeyIdentifier, minus, numericKeypadKey, periodKey, prepareValueToFormatting, toFixed, unformat } from './NumberInput.utils';
function noop() {}
var PlusIcon = function PlusIcon() {
  return /*#__PURE__*/React.createElement("svg", {
    width: "8",
    height: "8",
    viewBox: "0 0 8 8",
    xmlns: "http://www.w3.org/2000/svg"
  }, /*#__PURE__*/React.createElement("path", {
    d: "M4.5 0H3.5V3.5H0V4.5H3.5V8H4.5V4.5H8V3.5H4.5V0Z"
  }));
};
var MinusIcon = function MinusIcon() {
  return /*#__PURE__*/React.createElement("svg", {
    width: "8",
    height: "2",
    viewBox: "0 0 8 2",
    xmlns: "http://www.w3.org/2000/svg"
  }, /*#__PURE__*/React.createElement("path", {
    d: "M4.5 0.5H3.5H0V1.5H3.5H4.5H8V0.5H4.5Z"
  }));
};

/**

 The number input allows users to add numbers to a given form or table.
 The currency input will be used for data with a monetary value.
 Both components allow characters 0-9, periods, and commas. In order to avoid
 the loss of precision, the number length is limited by 15 digits.

 @since 10.19.0

 @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-numberinput--demo-number-input)

 @see [Design Guidelines](https://design.procore.com/number-and-currency-input)

 */
export var NumberInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var _ref$decimalScale = _ref.decimalScale,
    decimalScale = _ref$decimalScale === void 0 ? true : _ref$decimalScale,
    defaultValue = _ref.defaultValue,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$error = _ref.error,
    error = _ref$error === void 0 ? false : _ref$error,
    _ref$fillDecimalScale = _ref.fillDecimalScale,
    fillDecimalScale = _ref$fillDecimalScale === void 0 ? 'none' : _ref$fillDecimalScale,
    _locale = _ref.locale,
    _onChange = _ref.onChange,
    _ref$onKeyDown = _ref.onKeyDown,
    _onKeyDown = _ref$onKeyDown === void 0 ? noop : _ref$onKeyDown,
    _ref$onBlur = _ref.onBlur,
    _onBlur = _ref$onBlur === void 0 ? noop : _ref$onBlur,
    _ref$prefix = _ref.prefix,
    prefix = _ref$prefix === void 0 ? emptyString : _ref$prefix,
    readOnly = _ref.readOnly,
    _ref$step = _ref.step,
    step = _ref$step === void 0 ? 0 : _ref$step,
    style = _ref.style,
    _ref$suffix = _ref.suffix,
    suffix = _ref$suffix === void 0 ? emptyString : _ref$suffix,
    value = _ref.value,
    qa = _ref.qa,
    props = _objectWithoutProperties(_ref, _excluded);
  var I18n = useI18nContext();
  var contextLocale = _locale || I18n.locale || defaultLocale;
  var inputRef = React.useRef(null);
  var _useNumberFormat = useNumberFormat({
      decimalScale: decimalScale,
      fillDecimalScale: fillDecimalScale,
      locale: contextLocale
    }),
    verifiedDecimalScale = _useNumberFormat.decimalScale,
    fillDecimalScaleOnBlur = _useNumberFormat.fillDecimalScaleOnBlur,
    fixedDecimalScale = _useNumberFormat.fixedDecimalScale,
    formatValue = _useNumberFormat.formatValue,
    getValueLengthInfo = _useNumberFormat.getValueLengthInfo,
    locale = _useNumberFormat.locale;
  var isControlled = value !== undefined;
  var isControlledWithoutOnChangeHandlerAndReadOnlyAttribute = isControlled && !_onChange && !readOnly;
  var hasIncrementer = step > 0 && !readOnly;
  var _React$useMemo = React.useMemo(function () {
      return getSeparators(locale);
    }, [locale]),
    group = _React$useMemo.group,
    decimal = _React$useMemo.decimal;
  var decimalSeparatorKey = React.useMemo(function () {
    return decimal === periodKey ? periodKey : commaKey;
  }, [decimal]);
  var inputPadding = React.useMemo(function () {
    var fontContext = "".concat(addonRootFontSize, " \"").concat(addonRootFontFamily, "\"");
    if (prefix || suffix) {
      var element = document.createElement('canvas');
      var context = element === null || element === void 0 ? void 0 : element.getContext('2d');
      if (context) {
        context.font = fontContext;
        var extraBasePadding = inputDefaultXPadding + addonRootPadding;
        var suffixPadding = extraBasePadding + Math.ceil(context.measureText(suffix).width);
        var getRightPadding = function getRightPadding() {
          if (hasIncrementer && suffix) {
            return suffixPadding + spacing.xl;
          }
          if (suffix) {
            return suffixPadding;
          }
          return null;
        };
        return {
          left: prefix ? extraBasePadding + Math.ceil(context.measureText(prefix).width) : inputDefaultXPadding,
          right: getRightPadding()
        };
      }
    }
    return {
      left: inputDefaultXPadding,
      right: null
    };
  }, [prefix, suffix, hasIncrementer]);
  var getValueChange = React.useCallback(function (value) {
    var _unformat = unformat(locale, value),
      parsedNumber = _unformat.parsedNumber;
    return {
      value: value,
      parsedNumber: isNaN(parsedNumber) ? null : parsedNumber
    };
  }, [locale]);
  var externalOnChange = React.useCallback(function (value) {
    return _onChange && _onChange(getValueChange(value));
  }, [_onChange, getValueChange]);
  var _React$useState = React.useState(formatValue(defaultValue)),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    inputValue = _React$useState2[0],
    setInputValue = _React$useState2[1];
  var _React$useState3 = React.useState(isControlled ? formatValue(value) : inputValue),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    prevValue = _React$useState4[0],
    setPrevValue = _React$useState4[1];
  var _React$useState5 = React.useState({
      selectionStart: 0,
      selectionEnd: 0,
      selection: emptyString
    }),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    prevCursorPosition = _React$useState6[0],
    setPrevCursorPosition = _React$useState6[1];
  var _React$useState7 = React.useState(),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    pressedKey = _React$useState8[0],
    setPressedKey = _React$useState8[1];
  var prevLocale = usePrevious(locale);

  // eslint-disable-next-line react-hooks/exhaustive-deps
  React.useLayoutEffect(function () {
    var formattedValue = formatValue(value);
    if (isControlled && inputValue !== formattedValue) {
      setInputValue(formattedValue);
    }
    if (isControlledWithoutOnChangeHandlerAndReadOnlyAttribute) {
      console.error("Warning: Failed prop type: You provided a `value` prop to a form field without an `onChange` handler.\n        This will render a read-only field. If the field should be mutable use `defaultValue`.\n        Otherwise, set either `onChange` or `readOnly`.");
    }
  }, [value]);
  React.useEffect(function () {
    if (prevLocale && !identicalLocales(prevLocale, locale)) {
      setInputValue(function (prev) {
        var newValue = formatValue(unformat(prevLocale, prev).parsedNumber);
        externalOnChange(newValue);
        return newValue;
      });
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [prevLocale, formatValue]);
  React.useLayoutEffect(function () {
    var _inputRef$current;
    var displayValue = ((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) || '';
    if (!_onChange || !displayValue) {
      return;
    }
    var formattedValue = formatValue(value);
    if (displayValue !== formattedValue) {
      var lastChar = displayValue[displayValue.length - 1];
      var lastCharIsPending = [periodKey, commaKey].includes(lastChar);
      var decimals = displayValue.split(decimal)[1] || '';
      var lastDecimalIsZero = decimals && decimals[decimals.length - 1] === '0';
      var onlyMinusDisplayed = displayValue === minus;

      // a client state and display mismatch is only valid when
      if (lastCharIsPending || lastDecimalIsZero || onlyMinusDisplayed) {
        return;
      }

      // otherwise sync display with client state
      setInputValue(formattedValue);
    }
  });
  var getNewValueAndCursorPosition = function getNewValueAndCursorPosition(value, pressedKey) {
    var preparedValue = prepareValueToFormatting(decimal, decimalSeparatorKey, group, pressedKey, prevCursorPosition, prevValue, verifiedDecimalScale, value);
    var newValue = formatValue(preparedValue);
    return {
      newValue: newValue,
      newCursorPosition: getNewCursorPosition(decimal, decimalSeparatorKey, group, newValue, pressedKey, prevCursorPosition, prevValue, value, verifiedDecimalScale, locale, fillDecimalScale)
    };
  };
  var adjustCursor = function adjustCursor(newPosition) {
    var _inputRef$current2;
    (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.setSelectionRange(newPosition, newPosition);
    // Mobile Chrome adjustment
    setTimeout(function () {
      var _inputRef$current3;
      return (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.setSelectionRange(newPosition, newPosition);
    }, 0);
  };
  var makeStep = function makeStep() {
    var down = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    var getSignificantPrecision = function getSignificantPrecision(fraction) {
      var reversedFraction = fraction.split(emptyString).reverse();
      var indexOfLastSignificantFractionDigit = findIndex(function (i) {
        return i !== '0';
      }, reversedFraction);
      return indexOfLastSignificantFractionDigit > -1 ? reversedFraction.slice(indexOfLastSignificantFractionDigit).length : 0;
    };
    var _unformat2 = unformat(locale, inputValue),
      parsedNumber = _unformat2.parsedNumber,
      fraction = _unformat2.fraction;
    var _unformat3 = unformat(locale, step),
      stepFraction = _unformat3.fraction;
    var prevValuePrecision = fraction.length || 0;
    var prevValueSignificantPrecision = getSignificantPrecision(fraction);
    var rawStepPrecision = stepFraction.length || 0;
    var rawStepPrecisionExceedsDecimalScale = rawStepPrecision > verifiedDecimalScale;
    var stepPrecision = rawStepPrecisionExceedsDecimalScale ? verifiedDecimalScale : rawStepPrecision;
    if (rawStepPrecisionExceedsDecimalScale) {
      console.warn("WARNING: Step's value was rounded since its scale (".concat(rawStepPrecision, ") exceeds the decimal scale (").concat(verifiedDecimalScale, ")."));
    }
    var diff = toFixed(step, stepPrecision) * (down ? -1 : 1);
    var precision = Math.max(stepPrecision, fixedDecimalScale ? verifiedDecimalScale : prevValuePrecision);
    var significantPrecision = Math.max(prevValueSignificantPrecision, stepPrecision);
    var calculated = inputValue ? ((parsedNumber || 0) + diff).toFixed(significantPrecision) : diff;
    var _getValueLengthInfo = getValueLengthInfo(calculated, true),
      isSafeLength = _getValueLengthInfo.isSafeLength,
      isSafeIntegerLength = _getValueLengthInfo.isSafeIntegerLength;
    var rejectStepByLengthLimit = !isSafeLength || !isSafeIntegerLength;
    if (rejectStepByLengthLimit) {
      console.warn("WARNING: Incrementer's step was not fulfilled since result oversteps input ".concat(maxDigitLength, "-digit limit and can't be presented without a loss of precision."));
      return;
    }
    var formatted = format(locale, precision, 'always', calculated, true);
    setInputValue(formatted);
    externalOnChange(formatted);
  };
  var internalOnKeyDown = function internalOnKeyDown(e) {
    var ctrlKey = e.ctrlKey,
      metaKey = e.metaKey,
      key = e.key,
      _e$target = e.target,
      value = _e$target.value,
      selectionStart = _e$target.selectionStart,
      selectionEnd = _e$target.selectionEnd;
    var selection = value.slice(selectionStart, selectionEnd);
    setPressedKey(key);
    setPrevCursorPosition({
      selectionStart: selectionStart,
      selectionEnd: selectionEnd,
      selection: selection
    });
    setPrevValue(value);
    var preserveDecimalSeparator = function preserveDecimalSeparator() {
      var decimalBackspaced = !selection && [backspaceKey].includes(key) && value[selectionEnd - 1] === decimal;
      var decimalDeleted = !selection && [deleteKey, numericKeypadKey].includes(key) && value[selectionEnd] === decimal;
      var nonReplacingKeys = [metaKeyIdentifier, controlKey, highlightAllKey, copyKey].includes(key) && (ctrlKey || metaKey);
      var decimalReplacedAsSelection = selection && selection.includes(decimal) && selection.length < value.length && !nonReplacingKeys;
      var preserveDecimal = decimalBackspaced || decimalDeleted || decimalReplacedAsSelection;
      if (preserveDecimal) {
        var base = decimalReplacedAsSelection ? selectionStart : selectionEnd;
        var shift = decimalBackspaced && -1 || decimalDeleted && 1 || 0;
        var cursorPosition = base + shift;
        e.preventDefault();
        adjustCursor(cursorPosition);
      }
    };
    var isDecimalSeparatorPreserved = function isDecimalSeparatorPreserved() {
      var _getValueLengthInfo2 = getValueLengthInfo(value),
        safeIntegerLength = _getValueLengthInfo2.safeIntegerLength,
        integerLength = _getValueLengthInfo2.integerLength,
        fractionLength = _getValueLengthInfo2.fractionLength;
      var decimalSeparatorCanNotBeRemoved = safeIntegerLength - integerLength < fractionLength;
      return fillDecimalScaleOnBlur && decimalSeparatorCanNotBeRemoved || fixedDecimalScale;
    };
    if (isDecimalSeparatorPreserved()) {
      preserveDecimalSeparator();
    }
    var handleIncrementer = function handleIncrementer() {
      switch (key) {
        case 'ArrowUp':
        case 'Up':
          e.preventDefault();
          makeStep();
          break;
        case 'ArrowDown':
        case 'Down':
          e.preventDefault();
          makeStep(true);
          break;
      }
    };
    if (hasIncrementer) {
      handleIncrementer();
    }
    _onKeyDown(e);
  };
  var internalOnChange = function internalOnChange(e) {
    if (isControlledWithoutOnChangeHandlerAndReadOnlyAttribute) return;
    var value = e.target.value,
      inputType = e.nativeEvent.inputType;
    var _getNewValueAndCursor = getNewValueAndCursorPosition(value, identifyPressedKey(decimalSeparatorKey, inputType, pressedKey, prevValue, value)),
      newValue = _getNewValueAndCursor.newValue,
      newCursorPosition = _getNewValueAndCursor.newCursorPosition;
    // Prevent cursor flickering
    e.target.value = newValue;
    setInputValue(newValue);
    adjustCursor(newCursorPosition);
    if (newValue !== prevValue) {
      externalOnChange(newValue);
    }
  };
  var internalOnBlur = function internalOnBlur(e) {
    var _unformat4 = unformat(locale, inputValue),
      integer = _unformat4.integer,
      fraction = _unformat4.fraction;
    var shouldValueBeCleared = inputValue === minus || inputValue === decimal || inputValue === "".concat(minus).concat(decimal);
    var shouldIntegerPartBeFilled = fraction.length > 0 && (integer === emptyString || integer === minus);
    var isDecimalSeparatorRedundant = verifiedDecimalScale > 0 && inputValue[inputValue.length - 1] === decimal && !fillDecimalScaleOnBlur;
    var isDecimalScaleNotFilled = verifiedDecimalScale - fraction.length > 0;
    var shouldDecimalScaleBeFilled = fillDecimalScaleOnBlur && isDecimalScaleNotFilled;
    if (shouldValueBeCleared || shouldIntegerPartBeFilled || isDecimalSeparatorRedundant || shouldDecimalScaleBeFilled) {
      var getNewValue = function getNewValue() {
        if (shouldValueBeCleared) {
          return emptyString;
        }
        if (shouldIntegerPartBeFilled) {
          var numberOfZerosToPad = verifiedDecimalScale - fraction.length;
          return "".concat(integer, "0").concat(decimal).concat(shouldDecimalScaleBeFilled ? fraction.concat(Array.from({
            length: numberOfZerosToPad
          }, function (_) {
            return '0';
          }).join(emptyString)) : fraction);
        }
        if (isDecimalSeparatorRedundant) {
          return inputValue.replace(new RegExp("[".concat(decimal, "]"), 'g'), emptyString);
        }
        if (shouldDecimalScaleBeFilled) {
          return format(locale, verifiedDecimalScale, 'always', inputValue);
        }
        return inputValue;
      };
      var newValue = getNewValue();
      setInputValue(newValue);
      externalOnChange(newValue);
    }
    _onBlur(e);
  };
  return /*#__PURE__*/React.createElement(StyledWrapper, {
    hasIncrementer: hasIncrementer,
    "data-qa": qa === null || qa === void 0 ? void 0 : qa.wrapper
  }, /*#__PURE__*/React.createElement(StyledInput, _extends({
    value: inputValue,
    disabled: disabled,
    error: error,
    onKeyDown: internalOnKeyDown,
    onChange: internalOnChange,
    onBlur: internalOnBlur,
    inputMode: "numeric",
    readOnly: readOnly,
    style: _objectSpread(_objectSpread({}, style), {
      paddingLeft: "".concat(inputPadding.left, "px"),
      paddingRight: "".concat(inputPadding.right, "px")
    })
  }, props, {
    ref: mergeRefs(ref, inputRef)
  })), prefix && /*#__PURE__*/React.createElement(StyledPrefix, {
    disabled: disabled
  }, prefix), suffix && /*#__PURE__*/React.createElement(StyledSuffix, {
    withIncrementer: hasIncrementer,
    disabled: disabled
  }, suffix), hasIncrementer && /*#__PURE__*/React.createElement(StyledIncrementerWrapper, null, /*#__PURE__*/React.createElement(StyledIncrementerButton, {
    "aria-hidden": "true",
    type: "button",
    disabled: disabled,
    tabIndex: -1,
    "data-qa": qa === null || qa === void 0 ? void 0 : qa.increment,
    onClick: function onClick() {
      return makeStep();
    }
  }, /*#__PURE__*/React.createElement(PlusIcon, null)), /*#__PURE__*/React.createElement(StyledIncrementerButton, {
    "aria-hidden": "true",
    type: "button",
    disabled: disabled,
    tabIndex: -1,
    "data-qa": qa === null || qa === void 0 ? void 0 : qa.decrement,
    onClick: function onClick() {
      return makeStep(true);
    }
  }, /*#__PURE__*/React.createElement(MinusIcon, null))));
});
NumberInput.displayName = 'NumberInput';
export var getCurrencyProps = function getCurrencyProps(locale, _decimalScale, symbol, currencyIsoCode, currencyDisplay) {
  var _parts$find, _parts$find2;
  var currencyOptions = {
    locale: locale,
    currencyIsoCode: currencyIsoCode || 'USD',
    currencyDisplay: currencyDisplay || 'narrowSymbol'
  };
  var parts = formatCurrencyToParts(1, currencyOptions);
  var formatterDecimalScale = ((_parts$find = parts.find(function (part) {
    return part.type === 'fraction';
  })) === null || _parts$find === void 0 ? void 0 : _parts$find.value.length) || 0;
  var decimalScale = _decimalScale || formatterDecimalScale;
  var placement = parts.findIndex(function (object) {
    return object.type === 'currency';
  }) < parts.findIndex(function (part) {
    return part.type === 'integer';
  }) ? 'prefix' : 'suffix';
  var currencyIsoSymbol = currencyIsoCode ? (_parts$find2 = parts.find(function (part) {
    return part.type === 'currency';
  })) === null || _parts$find2 === void 0 ? void 0 : _parts$find2.value.toString() : undefined;
  var currencyProps = placement === 'prefix' ? {
    decimalScale: decimalScale,
    prefix: currencyIsoSymbol || symbol || ''
  } : {
    decimalScale: decimalScale,
    suffix: currencyIsoSymbol || symbol || ''
  };
  return currencyProps;
};
export var CurrencyInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
  var currencyDisplay = _ref2.currencyDisplay,
    currencyIsoCode = _ref2.currencyIsoCode,
    _decimalScale = _ref2.decimalScale,
    _ref2$fillDecimalScal = _ref2.fillDecimalScale,
    fillDecimalScale = _ref2$fillDecimalScal === void 0 ? defaultCurrencyFillDecimalScale : _ref2$fillDecimalScal,
    _ref2$prefix = _ref2.prefix,
    prefix = _ref2$prefix === void 0 ? defaultCurrencyInputPrefix : _ref2$prefix,
    suffix = _ref2.suffix,
    props = _objectWithoutProperties(_ref2, _excluded2);
  var I18n = useI18nContext();
  var contextLocale = props.locale || I18n.locale || defaultLocale;
  var currencyProps = getCurrencyProps(contextLocale, _decimalScale, prefix || suffix, currencyIsoCode, currencyDisplay);
  return /*#__PURE__*/React.createElement(NumberInput, _extends({
    fillDecimalScale: fillDecimalScale
  }, props, currencyProps, {
    ref: ref
  }));
});
CurrencyInput.displayName = 'CurrencyInput';
//# sourceMappingURL=NumberInput.js.map