"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _context = require("../config-provider/context");

var _components = require("../components");

var _icon = _interopRequireDefault(require("../icon"));

var InputNumberRc = _components.RcInputNumber.default;
var UpLine = _icon.default.UpLine,
    DownLine = _icon.default.DownLine;
/* eslint-disable no-shadow */

var inputWrapSize;

(function (inputWrapSize) {
  inputWrapSize["small"] = "sm";
  inputWrapSize["medium"] = "";
  inputWrapSize["large"] = "lg";
})(inputWrapSize || (inputWrapSize = {}));

var InputNumber = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName,
      size = _React$useContext.size;

  var inputNumberRef = ref || _react.default.useRef(null);

  var className = props.className,
      customSize = props.size,
      prefixCls = props.prefixCls,
      bordered = props.bordered,
      readOnly = props.readOnly,
      addonBefore = props.addonBefore,
      addonAfter = props.addonAfter,
      controls = props.controls,
      style = props.style,
      others = (0, _objectWithoutProperties2.default)(props, ["className", "size", "prefixCls", "bordered", "readOnly", "addonBefore", "addonAfter", "controls", "style"]);
  var inputNumberCls = getPrefixClassName('input-number', prefixCls);

  var upIcon = /*#__PURE__*/_react.default.createElement(UpLine, {
    className: "".concat(prefixCls, "-handler-up-inner")
  });

  var downIcon = /*#__PURE__*/_react.default.createElement(DownLine, {
    className: "".concat(prefixCls, "-handler-down-inner")
  });

  var endSize = customSize || size;
  var sizeSuffixCls = inputWrapSize[endSize];
  var endCls = (0, _classnames.default)(sizeSuffixCls && "".concat(inputNumberCls, "-").concat(sizeSuffixCls), !bordered && "".concat(inputNumberCls, "-borderless"), !addonAfter && !addonBefore && className);

  var renderInputNumber = function renderInputNumber() {
    var inputNumberNode = /*#__PURE__*/_react.default.createElement(InputNumberRc, Object.assign({
      ref: inputNumberRef,
      className: endCls,
      upHandler: upIcon,
      downHandler: downIcon,
      prefixCls: inputNumberCls,
      readOnly: readOnly,
      controls: controls,
      style: !addonAfter && !addonBefore ? style : null
    }, others));

    if (!!addonAfter || !!addonBefore) {
      var addonCls = (0, _classnames.default)(sizeSuffixCls && "".concat(inputNumberCls, "-").concat(sizeSuffixCls), "".concat(inputNumberCls, "-group"), !!addonBefore && "".concat(inputNumberCls, "-group-addonBefore"), !!addonAfter && "".concat(inputNumberCls, "-group-addonAfter"), className);
      var addBef = (0, _classnames.default)("".concat(inputNumberCls, "-addonBefore"));
      var addEnd = (0, _classnames.default)("".concat(inputNumberCls, "-addonAfter"));
      return /*#__PURE__*/_react.default.createElement("div", {
        className: addonCls,
        style: style
      }, addonBefore && /*#__PURE__*/_react.default.createElement("span", {
        className: addBef
      }, addonBefore), inputNumberNode, addonAfter && /*#__PURE__*/_react.default.createElement("span", {
        className: addEnd
      }, addonAfter));
    }

    return inputNumberNode;
  };

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderInputNumber());
});

InputNumber.displayName = 'InputNumber';
InputNumber.defaultProps = {
  // size: 'medium',
  bordered: true
};
var _default = InputNumber;
exports.default = _default;