'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 DayCalendarTable = require('./table/DayCalendarTable.js');
var jsxRuntime = require('react/jsx-runtime');

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

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