"use strict";

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

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

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 _moment = _interopRequireDefault(require("moment"));

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

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

  function MonthYearDropDown() {
    var _this;

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

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleChangeMonth", function (_ref) {
      var value = _ref.target.value;
      var _this$props = _this.props,
          month = _this$props.month,
          onMonthSelect = _this$props.onMonthSelect;
      onMonthSelect(month, value);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleChangeYear", function (_ref2) {
      var value = _ref2.target.value;
      var _this$props2 = _this.props,
          month = _this$props2.month,
          onYearSelect = _this$props2.onYearSelect;
      onYearSelect(month, value);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleStopPropagation", function (e) {
      return e.stopPropagation();
    });
    return _this;
  }

  var _proto = MonthYearDropDown.prototype;

  _proto.render = function render() {
    var _this$props3 = this.props,
        month = _this$props3.month,
        monthAriaLabel = _this$props3.monthAriaLabel,
        yearAriaLabel = _this$props3.yearAriaLabel,
        yearsAfterCurrent = _this$props3.yearsAfterCurrent,
        yearsBeforeCurrent = _this$props3.yearsBeforeCurrent;
    var yearList = (0, _datePickerHelpers.getSiblingYearList)((0, _moment.default)().year(), yearsBeforeCurrent, yearsAfterCurrent);
    return _react.default.createElement("div", {
      "data-test-automation-id": "monthYearDropDown",
      className: "rc-month-year-dropdown-wrapper",
      onKeyDown: this.handleStopPropagation,
      onClick: this.handleStopPropagation,
      onMouseUp: this.handleStopPropagation,
      onKeyUp: this.handleStopPropagation
    }, _react.default.createElement("select", {
      "data-test-automation-id": "monthDropDown",
      autoFocus: true,
      className: "month-dropdown form-control",
      value: month.month(),
      "aria-label": monthAriaLabel,
      onChange: this.handleChangeMonth
    }, _moment.default.months().map(function (label, value) {
      return _react.default.createElement("option", {
        key: value,
        value: value
      }, label);
    })), _react.default.createElement("select", {
      "data-test-automation-id": "yearDropDown",
      className: "year-dropdown form-control",
      value: month.year(),
      onChange: this.handleChangeYear,
      "aria-label": yearAriaLabel
    }, yearList.map(function (year) {
      return _react.default.createElement("option", {
        key: year,
        value: year
      }, year);
    })));
  };

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

exports.MonthYearDropDown = MonthYearDropDown;
(0, _defineProperty2.default)(MonthYearDropDown, "propTypes", {
  month: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.object]).isRequired,
  onMonthSelect: _propTypes.default.func.isRequired,
  onYearSelect: _propTypes.default.func.isRequired,
  monthAriaLabel: _propTypes.default.string.isRequired,
  yearAriaLabel: _propTypes.default.string.isRequired,
  yearsBeforeCurrent: _propTypes.default.number.isRequired,
  yearsAfterCurrent: _propTypes.default.number.isRequired
});