"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PlusMinusInput = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _withWidth = _interopRequireDefault(require("@material-ui/core/withWidth"));
var _styles = require("@material-ui/core/styles");
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
var _Input = _interopRequireDefault(require("@material-ui/core/Input"));
var _InputAdornment = _interopRequireDefault(require("@material-ui/core/InputAdornment"));
var _RemoveCircle = _interopRequireDefault(require("../../../../Resources/Icons/MaterialUI/Icons/RemoveCircle"));
var _AddCircle = _interopRequireDefault(require("../../../../Resources/Icons/MaterialUI/Icons/AddCircle"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var styles = function styles(theme) {
  return {
    disabledIncrementButton: {
      opacity: 0.2
    },
    disabledDecrementButton: {
      opacity: 0.2
    },
    activeIncrementButton: {
      opacity: 1,
      cursor: 'pointer',
      color: theme.palette.text.secondary
    },
    activeDecrementButton: {
      opacity: 1,
      cursor: 'pointer',
      color: theme.palette.text.secondary
    },
    itemText: {
      fontSize: 15,
      color: theme.palette.text.secondary,
      textAlign: 'center',
      lineHeight: 2.1,
      cursor: 'default',
      height: 33
    }
  };
};
var PlusMinusInput = exports.PlusMinusInput = (0, _withWidth["default"])()((0, _styles.withStyles)(styles, {
  name: 'PlusMinusInput'
})(function (props) {
  var increment = function increment() {
    var onChangeValue = props.onChangeValue,
      maxSize = props.maxSize,
      value = props.value;
    if ((0, _isFunction["default"])(onChangeValue)) {
      var intValue = parseInt(value);
      intValue < maxSize && onChangeValue(intValue + 1);
    }
  };
  var decrement = function decrement() {
    var onChangeValue = props.onChangeValue,
      minSize = props.minSize,
      value = props.value;
    if ((0, _isFunction["default"])(onChangeValue)) {
      var intValue = parseInt(value);
      intValue > minSize && onChangeValue(intValue - 1);
    }
  };
  var maxSize = props.maxSize,
    minSize = props.minSize,
    value = props.value,
    classes = props.classes;
  var disableIncrementButton = value < maxSize ? classes.activeIncrementButton : classes.disabledIncrementButton;
  var disableDecrementButton = value > minSize ? classes.activeDecrementButton : classes.disabledDecrementButton;
  return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_Input["default"], {
    fullWidth: true,
    readOnly: true,
    classes: {
      input: classes.itemText
    },
    value: parseInt(value),
    min: minSize,
    max: maxSize,
    startAdornment: /*#__PURE__*/_react["default"].createElement(_InputAdornment["default"], {
      className: disableDecrementButton,
      position: "start"
    }, /*#__PURE__*/_react["default"].createElement(_RemoveCircle["default"], {
      onClick: decrement
    })),
    endAdornment: /*#__PURE__*/_react["default"].createElement(_InputAdornment["default"], {
      className: disableIncrementButton,
      position: "end"
    }, /*#__PURE__*/_react["default"].createElement(_AddCircle["default"], {
      onClick: increment
    }))
  }));
}));