'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var types = require('../store/types.js');
var constants = require('../utils/constants.js');
var calendarGridHelper = require('../utils/calendarGridHelper.js');
var calendarRangeHelper = require('../utils/calendarRangeHelper.js');
var getDateWithModification = require('../utils/getDateWithModification.js');

/**
 * Хук для получения списка месяцев.
 */
var useMonths = function useMonths(_ref) {
  var date = _ref.date,
    value = _ref.value,
    eventList = _ref.eventList,
    disabledList = _ref.disabledList,
    min = _ref.min,
    max = _ref.max,
    _ref$locale = _ref.locale,
    locale = _ref$locale === void 0 ? 'ru' : _ref$locale,
    includeEdgeDates = _ref.includeEdgeDates;
  return React.useMemo(function () {
    var months = constants.SHORT_MONTH_NAME[locale].map(function (monthName, monthIndex) {
      return {
        monthName: monthName,
        monthIndex: monthIndex,
        isCurrent: calendarGridHelper.isCurrentMonth(date, monthIndex),
        isSelected: Array.isArray(value) ? Boolean(value.find(function (v) {
          return calendarGridHelper.isSelectedMonth(date, monthIndex, v);
        })) : calendarGridHelper.isSelectedMonth(date, monthIndex, value),
        inRange: Array.isArray(value) ? calendarRangeHelper.isDateInRange(date.year, monthIndex, 1, value) : false,
        monthFullName: constants.MONTH_NAMES[locale][monthIndex],
        date: {
          year: date.year,
          monthIndex: monthIndex,
          day: 1
        }
      };
    });
    if (eventList !== null && eventList !== void 0 && eventList.length || disabledList !== null && disabledList !== void 0 && disabledList.length || max || min) {
      var modifiedMonths = getDateWithModification.getDatesWithModifications({
        dates: months,
        type: types.CalendarState.Months,
        min: min,
        max: max,
        includeEdgeDates: includeEdgeDates,
        eventList: eventList,
        disabledList: disabledList
      });
      return calendarGridHelper.getMatrix(modifiedMonths, 3);
    }
    return calendarGridHelper.getMatrix(months, 3);
  }, [date, value, eventList, disabledList, max, min, locale]);
};

exports.useMonths = useMonths;
