"use strict";

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

exports.__esModule = true;
exports.PureListSorter = void 0;

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

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _CommonListSorter = require("./common/CommonListSorter");

var PureListSorter =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(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;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_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 = (0, _objectWithoutPropertiesLoose2.default)(_this$props2, ["currentSortingProperty", "currentSortingDirection"]);
    return _react.default.createElement(_CommonListSorter.CommonListSorter, (0, _extends2.default)({}, props, {
      onChangeSorting: this.handleChangeSorting,
      direction: this.getDirection()
    }));
  };

  return PureListSorter;
}(_react.default.Component);

exports.PureListSorter = PureListSorter;
(0, _defineProperty2.default)(PureListSorter, "propTypes", {
  currentSortingDirection: _propTypes.default.string.isRequired,
  onChangeSorting: _propTypes.default.func.isRequired,
  property: _propTypes.default.string.isRequired,
  currentSortingProperty: _propTypes.default.string.isRequired
});