function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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; }

import React from 'react';
import PropTypes from 'prop-types';
import { events, func } from '../../util';
import Balloon from '../../balloon';
import { getPercent } from '../utils';
var Tooltip = Balloon.Tooltip;
var noop = func.noop;

function _getStyle(min, max, value, rtl) {
  if (rtl) {
    return {
      left: "".concat(getPercent(min, max, max + min - value[1]), "%"),
      right: "".concat(getPercent(min, max, value[0]), "%")
    };
  }

  return {
    left: "".concat(getPercent(min, max, value[0]), "%"),
    right: "".concat(100 - getPercent(min, max, value[1]), "%")
  };
}

function sliderFrag(props) {
  var prefix = props.prefix,
      min = props.min,
      max = props.max,
      value = props.value,
      disabled = props.disabled,
      onMouseEnter = props.onMouseEnter,
      onMouseLeave = props.onMouseLeave,
      onMouseDown = props.onMouseDown,
      rtl = props.rtl;
  var activeClass = !disabled && props.hasMovingClass ? " ".concat(prefix, "range-active") : '';
  return React.createElement("div", {
    className: "".concat(prefix, "range-frag").concat(activeClass),
    style: _getStyle(min, max, value, rtl),
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave,
    onMouseDown: onMouseDown
  }, React.createElement("div", {
    className: "".concat(prefix, "range-selected")
  }), React.createElement("div", {
    className: "".concat(prefix, "range-slider")
  }, React.createElement("div", {
    className: "".concat(prefix, "range-slider-inner")
  })), React.createElement("div", {
    className: "".concat(prefix, "range-slider")
  }, React.createElement("div", {
    className: "".concat(prefix, "range-slider-inner")
  })));
}

sliderFrag.propTypes = {
  prefix: PropTypes.string,
  min: PropTypes.number,
  max: PropTypes.number,
  hasMovingClass: PropTypes.bool,
  onMouseEnter: PropTypes.func,
  onMouseLeave: PropTypes.func,
  onMouseDown: PropTypes.func,
  value: PropTypes.arrayOf(PropTypes.number),
  disabled: PropTypes.bool,
  rtl: PropTypes.bool
};

var FixedSlider =
/*#__PURE__*/
function (_React$Component) {
  _inherits(FixedSlider, _React$Component);

  function FixedSlider(props) {
    var _this;

    _classCallCheck(this, FixedSlider);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(FixedSlider).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "_onMouseDown", function () {
      _this.keyState = 'down';

      _this.setState({
        hasMovingClass: true
      });

      _this._addDocumentEvents();
    });

    _defineProperty(_assertThisInitialized(_this), "_onMouseUp", function () {
      if (_this.keyState === 'down') {
        _this.keyState = '';

        _this._removeDocumentEvents();

        _this.setState({
          hasMovingClass: false
        });
      }
    });

    _defineProperty(_assertThisInitialized(_this), "_addDocumentEvents", function () {
      _this._onMouseUpListener = events.on(document, 'mouseup', _this._onMouseUp);
    });

    _defineProperty(_assertThisInitialized(_this), "_removeDocumentEvents", function () {
      if (_this._onMouseUpListener) {
        _this._onMouseUpListener.off();

        _this._onMouseUpListener = null;
      }
    });

    _this.state = {
      hasMovingClass: false,
      tooltipAnimation: true
    };
    return _this;
  }

  _createClass(FixedSlider, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          hasTip = _this$props.hasTip,
          value = _this$props.value,
          tipRender = _this$props.tipRender,
          tooltipVisible = _this$props.tooltipVisible,
          hasMovingClass = _this$props.hasMovingClass;
      var addedProps = {
        hasMovingClass: hasMovingClass || this.state.hasMovingClass,
        onMouseDown: this._onMouseDown
      };
      return hasTip ? React.createElement(Tooltip, {
        popupContainer: function popupContainer(target) {
          return target.parentNode;
        },
        popupProps: {
          visible: tooltipVisible || hasMovingClass,
          animation: this.state.tooltipAnimation ? {
            "in": 'expandInUp',
            out: 'expandOutDown'
          } : false
        },
        type: "primary",
        trigger: sliderFrag(_objectSpread({}, this.props, {}, addedProps)),
        align: "t"
      }, tipRender("".concat(value[0], "-").concat(value[1]))) : sliderFrag(_objectSpread({}, this.props, {}, addedProps));
    }
  }]);

  return FixedSlider;
}(React.Component);

_defineProperty(FixedSlider, "propTypes", {
  hasTip: PropTypes.bool,
  tooltipVisible: PropTypes.bool,
  onTooltipVisibleChange: PropTypes.func,
  tooltipAnimation: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
  value: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
  tipRender: PropTypes.func,
  disabled: PropTypes.bool,
  hasMovingClass: PropTypes.bool,
  rtl: PropTypes.bool
});

_defineProperty(FixedSlider, "defaultProps", {
  disabled: false,
  hasTip: true,
  onChange: noop,
  onProcess: noop,
  tipRender: function tipRender(value) {
    return value;
  },
  reverse: false,
  rtl: false
});

export { FixedSlider as default };