import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { CommonListSorter } from './common/CommonListSorter';
export var PureListSorter =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(PureListSorter, _React$Component);

  function PureListSorter() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;

    _defineProperty(_assertThisInitialized(_this), "handleChangeSorting", function (property, direction) {
      _this.props.onChangeSorting(property, direction);
    });

    return _this;
  }

  var _proto = PureListSorter.prototype;

  _proto.getDirection = function getDirection() {
    var _this$props = this.props,
        currentSortingProperty = _this$props.currentSortingProperty,
        currentSortingDirection = _this$props.currentSortingDirection,
        property = _this$props.property;

    if (currentSortingProperty !== property) {
      return null;
    }

    return currentSortingDirection;
  };

  _proto.render = function render() {
    var _this$props2 = this.props,
        currentSortingProperty = _this$props2.currentSortingProperty,
        currentSortingDirection = _this$props2.currentSortingDirection,
        props = _objectWithoutPropertiesLoose(_this$props2, ["currentSortingProperty", "currentSortingDirection"]);

    return React.createElement(CommonListSorter, _extends({}, props, {
      onChangeSorting: this.handleChangeSorting,
      direction: this.getDirection()
    }));
  };

  return PureListSorter;
}(React.Component);

_defineProperty(PureListSorter, "propTypes", {
  currentSortingDirection: PropTypes.string.isRequired,
  onChangeSorting: PropTypes.func.isRequired,
  property: PropTypes.string.isRequired,
  currentSortingProperty: PropTypes.string.isRequired
});