import { useMemo } from "react";
import { SHORT_MONTH_NAME, isSelectedMonth, isCurrentMonth, getMatrix, MONTH_NAMES, isDateInRange, getDatesWithModifications } from "../utils";
import { CalendarState } from "../store/types";
/**
 * Хук для получения списка месяцев.
 */ export var useMonths = function useMonths(param) {
    var date = param.date, value = param.value, eventList = param.eventList, disabledList = param.disabledList, min = param.min, max = param.max, _param_locale = param.locale, locale = _param_locale === void 0 ? 'ru' : _param_locale, includeEdgeDates = param.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 ? void 0 : eventList.length) || (disabledList === null || disabledList === void 0 ? 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
    ]);
};
