import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import { Button } from '../../Button';
import { Block } from '../../Block';
import { isActiveRange, parsePreDefinedRangeConfig } from './datePickerHelpers';
export var PreDefinedRangesBlock =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(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 (_.isEmpty(ranges)) {
      return null;
    }

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

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

  return PreDefinedRangesBlock;
}(React.PureComponent);

_defineProperty(PreDefinedRangesBlock, "propTypes", {
  ranges: PropTypes.object,
  startDate: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.string]),
  endDate: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.string]),
  onPredefinedRangeButtonClick: PropTypes.func.isRequired
});

_defineProperty(PreDefinedRangesBlock, "defaultProps", {
  ranges: [],
  startDate: null,
  endDate: null
});