import { useMemo } from "react";
import { QUARTER_NAMES, getMatrix, isDateInRange, getDatesWithModifications, quarterDates, isSelectedMonth as isSelectedQuarter, isCurrentQuarter } from "../utils";
import { CalendarState } from "../store/types";
/**
 * Хук для получения списка месяцев.
 */ export var useQuarters = function useQuarters(param) {
    var date = param.date, value = param.value, eventList = param.eventList, disabledList = param.disabledList, min = param.min, max = param.max, includeEdgeDates = param.includeEdgeDates;
    return useMemo(function() {
        var quarters = QUARTER_NAMES.map(function(quarterName) {
            var _quarterDates_quarterName = quarterDates[quarterName], monthIndex = _quarterDates_quarterName.monthIndex, day = _quarterDates_quarterName.day;
            return {
                quarterName: quarterName,
                isCurrent: isCurrentQuarter(date, monthIndex),
                isSelected: Array.isArray(value) ? Boolean(value.find(function(v) {
                    return isSelectedQuarter(date, monthIndex, v);
                })) : isSelectedQuarter(date, monthIndex, value),
                inRange: Array.isArray(value) ? isDateInRange(date.year, monthIndex, day, value) : false,
                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 modifiedQuarters = getDatesWithModifications({
                dates: quarters,
                type: CalendarState.Quarters,
                min: min,
                max: max,
                includeEdgeDates: includeEdgeDates,
                eventList: eventList,
                disabledList: disabledList
            });
            return getMatrix(modifiedQuarters, 2);
        }
        return getMatrix(quarters, 2);
    }, [
        date,
        value,
        eventList,
        disabledList,
        max,
        min
    ]);
};
