"use strict";

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

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

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

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

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

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

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

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

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

var _tslib = require("tslib");

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

var _mobxReact = require("mobx-react");

var _noop = _interopRequireDefault(require("lodash/noop"));

var _omit = _interopRequireDefault(require("lodash/omit"));

var _slider = _interopRequireDefault(require("../../../lib/slider"));

var _NumberField2 = require("../number-field/NumberField");

var _excluded = ["dataSet", "onChange"];

var Range = /*#__PURE__*/function (_NumberField) {
  (0, _inherits2["default"])(Range, _NumberField);

  var _super = (0, _createSuper2["default"])(Range);

  function Range() {
    (0, _classCallCheck2["default"])(this, Range);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Range, [{
    key: "renderWrapper",
    value: function renderWrapper() {
      return /*#__PURE__*/_react["default"].createElement("label", (0, _extends2["default"])({
        key: "wrapper"
      }, (0, _omit["default"])(this.getWrapperProps(), ['style'])), this.renderTrack());
    }
  }, {
    key: "renderTrack",
    value: function renderTrack() {
      var _this = this;

      var _this$props = this.props,
          dataSet = _this$props.dataSet,
          _this$props$onChange = _this$props.onChange,
          _onChange = _this$props$onChange === void 0 ? _noop["default"] : _this$props$onChange,
          otherProps = (0, _objectWithoutProperties2["default"])(_this$props, _excluded),
          prefixCls = this.prefixCls;

      if (this.readOnly) {
        otherProps.value = this.value;
      }

      if (dataSet) {
        var props = {};

        if (otherProps.name) {
          var field = dataSet.getField(otherProps.name);

          if (field) {
            props = (0, _objectSpread2["default"])({}, field.getProps());
          }

          var current = dataSet.current;

          if (current) {
            props.value = current.get(otherProps.name);
          }
        }

        return /*#__PURE__*/_react["default"].createElement(_slider["default"], (0, _extends2["default"])({
          prefixCls: prefixCls
        }, otherProps, props, {
          onChange: function onChange(value) {
            _this.setValue(value);

            _onChange(value);
          }
        }));
      }

      return /*#__PURE__*/_react["default"].createElement(_slider["default"], (0, _extends2["default"])({
        prefixCls: prefixCls
      }, otherProps, {
        onChange: _onChange
      }));
    }
  }]);
  return Range;
}(_NumberField2.NumberField);

Range.displayName = 'Range';
Range.defaultProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _NumberField2.NumberField.defaultProps), {}, {
  suffixCls: 'range',
  min: 0,
  step: 1,
  max: 100,
  vertical: false,
  dots: false,
  marks: {},
  included: true,
  range: false,
  tipFormatter: null
});
Range = (0, _tslib.__decorate)([_mobxReact.observer], Range);
var _default = Range;
exports["default"] = _default;
//# sourceMappingURL=Range.js.map
