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