'use strict';

var formatting = require('@transferwise/formatting');
var React = require('react');
var reactIntl = require('react-intl');
var DateLookup_messages = require('../DateLookup.messages.js');
var DateHeader = require('../dateHeader/DateHeader.js');
var MonthCalendarTable = require('./table/MonthCalendarTable.js');
var jsxRuntime = require('react/jsx-runtime');

class MonthCalendar extends React.PureComponent {
  onMonthSelect = month => {
    this.props.onViewDateUpdate({
      month
    });
    this.props.onSelect();
  };
  selectPreviousYear = () => {
    this.props.onViewDateUpdate({
      year: this.props.viewYear - 1
    });
  };
  selectNextYear = () => {
    this.props.onViewDateUpdate({
      year: this.props.viewYear + 1
    });
  };
  render() {
    const {
      selectedDate,
      min,
      max,
      viewYear,
      intl: {
        locale,
        formatMessage
      },
      placeholder,
      onLabelClick
    } = this.props;
    return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [/*#__PURE__*/jsxRuntime.jsx(DateHeader, {
        dateMode: formatMessage(DateLookup_messages.year),
        label: formatting.formatDate(new Date(viewYear, 0), locale, {
          year: 'numeric'
        }),
        onLabelClick: onLabelClick,
        onPreviousClick: this.selectPreviousYear,
        onNextClick: this.selectNextYear
      }), /*#__PURE__*/jsxRuntime.jsx(MonthCalendarTable, {
        selectedDate: selectedDate,
        min: min,
        max: max,
        viewYear: viewYear,
        placeholder: placeholder,
        onSelect: this.onMonthSelect
      })]
    });
  }
}
var MonthCalendar$1 = reactIntl.injectIntl(MonthCalendar);

module.exports = MonthCalendar$1;
//# sourceMappingURL=MonthCalendar.js.map
