"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

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

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

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

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

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 _react = _interopRequireWildcard(require("react"));

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _slider = _interopRequireWildcard(require("../rc-components/slider"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _excluded = ["value", "dragging", "index"],
    _excluded2 = ["range", "prefixCls"];

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

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

  function Slider(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Slider);
    _this = _super.call(this, props);

    _this.toggleTooltipVisible = function (index, visible) {
      _this.setState(function (_ref) {
        var visibles = _ref.visibles;
        return {
          visibles: (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, visibles), {}, (0, _defineProperty2["default"])({}, index, visible))
        };
      });
    };

    _this.handleWithTooltip = function (_ref2) {
      var value = _ref2.value,
          dragging = _ref2.dragging,
          index = _ref2.index,
          restProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
      var _this$props = _this.props,
          tooltipPrefixCls = _this$props.tooltipPrefixCls,
          tooltipVisible = _this$props.tooltipVisible,
          tipFormatter = _this$props.tipFormatter;
      var visibles = _this.state.visibles;
      var visible = tooltipVisible ? visibles[index] || dragging : false;
      return /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        prefixCls: tooltipPrefixCls,
        title: tipFormatter ? tipFormatter(value) : "".concat(value),
        visible: visible,
        placement: "top",
        transitionName: "zoom-down",
        key: index
      }, /*#__PURE__*/_react["default"].createElement(_slider.Handle, (0, _extends2["default"])({}, restProps, {
        value: value,
        onMouseEnter: function onMouseEnter() {
          return _this.toggleTooltipVisible(index, true);
        },
        onMouseLeave: function onMouseLeave() {
          return _this.toggleTooltipVisible(index, false);
        }
      })));
    };

    _this.saveSlider = function (node) {
      _this.rcSlider = node;
    };

    _this.state = {
      visibles: {}
    };
    return _this;
  }

  (0, _createClass2["default"])(Slider, [{
    key: "focus",
    value: function focus() {
      this.rcSlider.focus();
    }
  }, {
    key: "blur",
    value: function blur() {
      this.rcSlider.focus();
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          range = _this$props2.range,
          customizePrefixCls = _this$props2.prefixCls,
          restProps = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded2);
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = getPrefixCls('slider', customizePrefixCls);

      if (range) {
        return /*#__PURE__*/_react["default"].createElement(_slider.Range, (0, _extends2["default"])({}, restProps, {
          ref: this.saveSlider,
          handle: this.handleWithTooltip,
          prefixCls: prefixCls
        }));
      }

      return /*#__PURE__*/_react["default"].createElement(_slider["default"], (0, _extends2["default"])({}, restProps, {
        ref: this.saveSlider,
        handle: this.handleWithTooltip,
        prefixCls: prefixCls
      }));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Slider;
}(_react.Component);

exports["default"] = Slider;
Slider.displayName = 'Slider';
Slider.defaultProps = {
  tooltipVisible: true,
  tipFormatter: function tipFormatter(value) {
    return value.toString();
  }
};
//# sourceMappingURL=index.js.map
