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 moment from 'moment';
import { getSiblingYearList } from './datePickerHelpers';
export var MonthYearDropDown =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_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);
    });

    _defineProperty(_assertThisInitialized(_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);
    });

    _defineProperty(_assertThisInitialized(_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 = getSiblingYearList(moment().year(), yearsBeforeCurrent, yearsAfterCurrent);
    return React.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.createElement("select", {
      "data-test-automation-id": "monthDropDown",
      autoFocus: true,
      className: "month-dropdown form-control",
      value: month.month(),
      "aria-label": monthAriaLabel,
      onChange: this.handleChangeMonth
    }, moment.months().map(function (label, value) {
      return React.createElement("option", {
        key: value,
        value: value
      }, label);
    })), React.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.createElement("option", {
        key: year,
        value: year
      }, year);
    })));
  };

  return MonthYearDropDown;
}(React.PureComponent);

_defineProperty(MonthYearDropDown, "propTypes", {
  month: PropTypes.oneOfType([PropTypes.number, PropTypes.object]).isRequired,
  onMonthSelect: PropTypes.func.isRequired,
  onYearSelect: PropTypes.func.isRequired,
  monthAriaLabel: PropTypes.string.isRequired,
  yearAriaLabel: PropTypes.string.isRequired,
  yearsBeforeCurrent: PropTypes.number.isRequired,
  yearsAfterCurrent: PropTypes.number.isRequired
});