import { useMemo } from 'react';
import { CalendarState } from '../store/types.js';
import { SHORT_MONTH_NAME, MONTH_NAMES } from '../utils/constants.js';
import { isCurrentMonth, isSelectedMonth, getMatrix } from '../utils/calendarGridHelper.js';
import { isDateInRange } from '../utils/calendarRangeHelper.js';
import { getDatesWithModifications } from '../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 useMemo(function () {
    var months = SHORT_MONTH_NAME[locale].map(function (monthName, monthIndex) {
      return {
        monthName: monthName,
        monthIndex: monthIndex,
        isCurrent: isCurrentMonth(date, monthIndex),
        isSelected: Array.isArray(value) ? Boolean(value.find(function (v) {
          return isSelectedMonth(date, monthIndex, v);
        })) : isSelectedMonth(date, monthIndex, value),
        inRange: Array.isArray(value) ? isDateInRange(date.year, monthIndex, 1, value) : false,
        monthFullName: 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 = getDatesWithModifications({
        dates: months,
        type: CalendarState.Months,
        min: min,
        max: max,
        includeEdgeDates: includeEdgeDates,
        eventList: eventList,
        disabledList: disabledList
      });
      return getMatrix(modifiedMonths, 3);
    }
    return getMatrix(months, 3);
  }, [date, value, eventList, disabledList, max, min, locale]);
};

export { useMonths };
