import { formatDate } from '@transferwise/formatting';
import { PureComponent } from 'react';
import { injectIntl } from 'react-intl';
import messages from '../DateLookup.messages.mjs';
import DateHeader from '../dateHeader/DateHeader.mjs';
import DayCalendarTable from './table/DayCalendarTable.mjs';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';

class DayCalendar extends 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__*/jsxs(Fragment, {
      children: [/*#__PURE__*/jsx(DateHeader, {
        label: formatDate(new Date(viewYear, viewMonth), locale, {
          month: monthFormat,
          year: 'numeric'
        }),
        dateMode: formatMessage(messages.month),
        onLabelClick: onLabelClick,
        onPreviousClick: this.selectPreviousMonth,
        onNextClick: this.selectNextMonth
      }), /*#__PURE__*/jsx(DayCalendarTable, {
        selectedDate,
        min,
        max,
        viewMonth,
        viewYear,
        onSelect
      })]
    });
  }
}
var DayCalendar$1 = injectIntl(DayCalendar);

export { DayCalendar$1 as default };
//# sourceMappingURL=DayCalendar.mjs.map
