"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactstrap = require("reactstrap");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var _getYearList = (minDate, maxDate) => {
  var minYear = minDate ? new Date(minDate).getFullYear() : 1970;
  var maxYear = maxDate ? new Date(maxDate).getFullYear() : 2045;
  var yList = [];
  for (var y = minYear; y <= maxYear; y++) {
    yList.push(y);
  }
  return yList;
};
var PickMonthDefault = _ref => {
  var {
    displayDate,
    minDate,
    maxDate,
    monthLabels,
    onChangeMonth,
    onChangeYear
  } = _ref;
  var [month, setMonth] = (0, _react.useState)(new Date(displayDate).getMonth());
  var [year, setYear] = (0, _react.useState)(new Date(displayDate).getFullYear());
  var [yearList, setYearList] = (0, _react.useState)(_getYearList(minDate, maxDate));
  (0, _react.useEffect)(() => {
    setMonth(new Date(displayDate).getMonth());
    setYear(new Date(displayDate).getFullYear());
  }, [displayDate]);
  (0, _react.useEffect)(() => {
    setYearList(_getYearList(minDate, maxDate));
  }, [minDate, maxDate]);
  var handleChangeMonth = ev => {
    var m = ev.target.value;
    setMonth(m);
    onChangeMonth(m);
  };
  var handleChangeYear = ev => {
    var y = ev.target.value;
    setYear(y);
    onChangeYear(y);
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "rdp-header-pick-month-default",
    style: {
      display: 'flex',
      flexFlow: 'row',
      flexWrap: 'nowrap'
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "rdp-header-pick-month-default-month",
    style: {
      flex: '2 1 auto'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
    type: "select",
    name: "rdp-header-pick-month-default-month",
    style: {
      lineHeight: "1.5",
      fontSize: "0.875rem",
      padding: "0.2rem"
    },
    value: month,
    onChange: handleChangeMonth
  }, monthLabels.map((lmonth, lidx) => {
    return /*#__PURE__*/_react.default.createElement("option", {
      key: "month_".concat(lidx),
      value: lidx
    }, lmonth);
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: "rdp-header-pick-month-default-year",
    style: {
      flex: '1 1 67px'
    }
  }, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
    type: "select",
    name: "rdp-header-pick-month-default-year",
    style: {
      lineHeight: "1.5",
      fontSize: "0.875rem",
      padding: "0.2rem"
    },
    value: year,
    onChange: handleChangeYear
  }, yearList.map(lyear => {
    return /*#__PURE__*/_react.default.createElement("option", {
      key: "year".concat(lyear),
      value: lyear
    }, lyear);
  }))));
};
var _default = exports.default = PickMonthDefault;