"use strict";

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

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

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 _lodash = _interopRequireDefault(require("lodash"));

var _Button = require("../../Button");

var _Block = require("../../Block");

var _datePickerHelpers = require("./datePickerHelpers");

var PreDefinedRangesBlock =
/*#__PURE__*/
function (_React$PureComponent) {
  (0, _inheritsLoose2.default)(PreDefinedRangesBlock, _React$PureComponent);

  function PreDefinedRangesBlock() {
    return _React$PureComponent.apply(this, arguments) || this;
  }

  var _proto = PreDefinedRangesBlock.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        ranges = _this$props.ranges,
        startDate = _this$props.startDate,
        endDate = _this$props.endDate,
        onPredefinedRangeButtonClick = _this$props.onPredefinedRangeButtonClick;

    if (_lodash.default.isEmpty(ranges)) {
      return null;
    }

    var rangeButtons = _lodash.default.map(ranges, function (rangeConfig, buttonText) {
      var range = (0, _datePickerHelpers.parsePreDefinedRangeConfig)(rangeConfig);
      return _react.default.createElement(_Button.Button, {
        key: buttonText,
        className: "range-predefined-btn",
        block: true,
        active: (0, _datePickerHelpers.isActiveRange)({
          range: range,
          startDate: startDate,
          endDate: endDate
        }),
        onClick: function onClick() {
          return onPredefinedRangeButtonClick({
            startDate: range.startDate,
            endDate: range.endDate
          });
        }
      }, buttonText);
    });

    return _react.default.createElement(_Block.Block, {
      className: "rc-datepicker-predefined-ranges"
    }, rangeButtons);
  };

  return PreDefinedRangesBlock;
}(_react.default.PureComponent);

exports.PreDefinedRangesBlock = PreDefinedRangesBlock;
(0, _defineProperty2.default)(PreDefinedRangesBlock, "propTypes", {
  ranges: _propTypes.default.object,
  startDate: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.object, _propTypes.default.string]),
  endDate: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.object, _propTypes.default.string]),
  onPredefinedRangeButtonClick: _propTypes.default.func.isRequired
});
(0, _defineProperty2.default)(PreDefinedRangesBlock, "defaultProps", {
  ranges: [],
  startDate: null,
  endDate: null
});