"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EditableCurrency = void 0;
var _react = _interopRequireWildcard(require("react"));
var _hooks = require("../../hooks");
var _utils = require("../../utils");
var _EditableContent = require("../EditableContent");
var _Tooltip = require("../Tooltip");
var _excluded = ["decimalLength", "decimalSeparator", "disableAbbreviation", "disabled", "disableMacros", "step", "thousandSeparator", "value", "onSave", "onCancel", "className", "allowEmptyValue", "onEnterKeyPress", "onClick", "onChange", "trimDecimals", "min", "max", "invalid"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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; }
var EditableCurrency = exports.EditableCurrency = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
  var _ref$decimalLength = _ref.decimalLength,
    decimalLength = _ref$decimalLength === void 0 ? 2 : _ref$decimalLength,
    _ref$decimalSeparator = _ref.decimalSeparator,
    decimalSeparator = _ref$decimalSeparator === void 0 ? "." : _ref$decimalSeparator,
    _ref$disableAbbreviat = _ref.disableAbbreviation,
    disableAbbreviation = _ref$disableAbbreviat === void 0 ? false : _ref$disableAbbreviat,
    disabled = _ref.disabled,
    _ref$disableMacros = _ref.disableMacros,
    disableMacros = _ref$disableMacros === void 0 ? false : _ref$disableMacros,
    _ref$step = _ref.step,
    step = _ref$step === void 0 ? 1 : _ref$step,
    _ref$thousandSeparato = _ref.thousandSeparator,
    thousandSeparator = _ref$thousandSeparato === void 0 ? "," : _ref$thousandSeparato,
    defaultValue = _ref.value,
    onSave = _ref.onSave,
    onCancel = _ref.onCancel,
    className = _ref.className,
    allowEmptyValue = _ref.allowEmptyValue,
    externalEnterKeyPress = _ref.onEnterKeyPress,
    externalOnClick = _ref.onClick,
    externalOnChange = _ref.onChange,
    _ref$trimDecimals = _ref.trimDecimals,
    trimDecimals = _ref$trimDecimals === void 0 ? true : _ref$trimDecimals,
    min = _ref.min,
    max = _ref.max,
    invalid = _ref.invalid,
    rest = _objectWithoutProperties(_ref, _excluded);
  var inputRef = (0, _react.useRef)(null);
  var handleRef = (0, _utils.useForkRef)(ref, inputRef);
  var _useInputNumber = (0, _hooks.useInputNumber)({
      decimalLength,
      decimalSeparator,
      disableAbbreviation,
      disableMacros,
      step,
      thousandSeparator,
      value: defaultValue,
      onSave,
      allowEmptyValue,
      onCancel,
      onChange: externalOnChange,
      onEnterKeyPress: externalEnterKeyPress,
      onClick: externalOnClick,
      trimDecimals,
      min,
      max,
      shortenThreshold: 10000
    }, inputRef),
    value = _useInputNumber.value,
    onBlur = _useInputNumber.onBlur,
    onKeyDown = _useInputNumber.onKeyDown,
    onChange = _useInputNumber.onChange,
    onClick = _useInputNumber.onClick,
    onDoubleClick = _useInputNumber.onDoubleClick,
    onFocus = _useInputNumber.onFocus,
    focused = _useInputNumber.focused,
    unformattedValue = _useInputNumber.unformattedValue;
  var formattedValue = (0, _react.useMemo)(function () {
    return focused ? value : (0, _utils.numberWithSeparator)(value !== null && value !== void 0 ? value : "", "", decimalSeparator);
  }, [focused, value, decimalSeparator]);
  return /*#__PURE__*/_react.default.createElement(_Tooltip.Tooltip, {
    title: (0, _utils.numberWithSeparator)(unformattedValue !== null && unformattedValue !== void 0 ? unformattedValue : "", thousandSeparator, decimalSeparator),
    disable: focused
  }, /*#__PURE__*/_react.default.createElement(_EditableContent.EditableContent, {
    disabled: disabled,
    ref: handleRef,
    className: className,
    invalid: invalid,
    inputProps: _objectSpread({
      value: formattedValue,
      onBlur: onBlur,
      onChange: onChange,
      onKeyDown: onKeyDown,
      onClick: onClick,
      onFocus: onFocus,
      onDoubleClick: onDoubleClick
    }, rest)
  }));
});
EditableCurrency.displayName = "EditableCurrency";
//# sourceMappingURL=EditableCurrency.js.map