import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/context';
import { RcInputNumber } from '../components';
import Icon from '../icon';
var InputNumberRc = RcInputNumber.default;
var UpLine = Icon.UpLine,
    DownLine = Icon.DownLine;
/* eslint-disable no-shadow */

var inputWrapSize;

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

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

  var inputNumberRef = ref || React.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 = _objectWithoutProperties(props, ["className", "size", "prefixCls", "bordered", "readOnly", "addonBefore", "addonAfter", "controls", "style"]);

  var inputNumberCls = getPrefixClassName('input-number', prefixCls);
  var upIcon = /*#__PURE__*/React.createElement(UpLine, {
    className: "".concat(prefixCls, "-handler-up-inner")
  });
  var downIcon = /*#__PURE__*/React.createElement(DownLine, {
    className: "".concat(prefixCls, "-handler-down-inner")
  });
  var endSize = customSize || size;
  var sizeSuffixCls = inputWrapSize[endSize];
  var endCls = classNames(sizeSuffixCls && "".concat(inputNumberCls, "-").concat(sizeSuffixCls), !bordered && "".concat(inputNumberCls, "-borderless"), !addonAfter && !addonBefore && className);

  var renderInputNumber = function renderInputNumber() {
    var inputNumberNode = /*#__PURE__*/React.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 = classNames(sizeSuffixCls && "".concat(inputNumberCls, "-").concat(sizeSuffixCls), "".concat(inputNumberCls, "-group"), !!addonBefore && "".concat(inputNumberCls, "-group-addonBefore"), !!addonAfter && "".concat(inputNumberCls, "-group-addonAfter"), className);
      var addBef = classNames("".concat(inputNumberCls, "-addonBefore"));
      var addEnd = classNames("".concat(inputNumberCls, "-addonAfter"));
      return /*#__PURE__*/React.createElement("div", {
        className: addonCls,
        style: style
      }, addonBefore && /*#__PURE__*/React.createElement("span", {
        className: addBef
      }, addonBefore), inputNumberNode, addonAfter && /*#__PURE__*/React.createElement("span", {
        className: addEnd
      }, addonAfter));
    }

    return inputNumberNode;
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, renderInputNumber());
});
InputNumber.displayName = 'InputNumber';
InputNumber.defaultProps = {
  // size: 'medium',
  bordered: true
};
export default InputNumber;