"use strict";

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

var _react = require("react");

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

var _getLocale = require("../../../utils/getLocale");

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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 = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var preCls = 'titaui-number-select';

function NumberSelect(props) {
  var _props$max = props.max,
      max = _props$max === void 0 ? 10 : _props$max,
      _props$min = props.min,
      min = _props$min === void 0 ? 2 : _props$min,
      _props$onChange = props.onChange,
      onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
      _props$defaultValue = props.defaultValue,
      defaultValue = _props$defaultValue === void 0 ? 2 : _props$defaultValue,
      _props$label = props.label,
      label = _props$label === void 0 ? (0, _getLocale.getLocale)('Mod_Editor') : _props$label;

  var _useState = (0, _react.useState)(defaultValue),
      _useState2 = _slicedToArray(_useState, 2),
      num = _useState2[0],
      setNum = _useState2[1];

  var addHandler = function addHandler() {
    if (num == max) return;
    setNum(num + 1);
    onChange(num + 1);
  };

  var minusHandler = function minusHandler() {
    if (num == min) return;
    setNum(num - 1);
    onChange(num - 1);
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(preCls)
  }, /*#__PURE__*/React.createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "--label"))
  }, label), /*#__PURE__*/React.createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "--action"))
  }, /*#__PURE__*/React.createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "--action-icon"), _defineProperty({}, "".concat(preCls, "--action-icon__disable"), num == min)),
    onClick: minusHandler
  }, "-"), /*#__PURE__*/React.createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "--value"))
  }, num), /*#__PURE__*/React.createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "--action-icon"), "".concat(preCls, "--action-icon-right"), _defineProperty({}, "".concat(preCls, "--action-icon__disable"), num == max)),
    onClick: addHandler
  }, "+")));
}

var _default = NumberSelect;
exports["default"] = _default;