import { useMemo } from "react";
import { SHORT_MONTH_NAME, isSelectedMonth, isCurrentMonth, getMatrix, MONTH_NAMES, isDateInRange, getDatesWithModifications } from "../utils";
import { CalendarState } from "../store/types";
/**
 * Хук для получения списка месяцев.
 */ export const useMonths = ({ date, value, eventList, disabledList, min, max, locale = 'ru', includeEdgeDates })=>useMemo(()=>{
        const months = SHORT_MONTH_NAME[locale].map((monthName, monthIndex)=>{
            return {
                monthName,
                monthIndex,
                isCurrent: isCurrentMonth(date, monthIndex),
                isSelected: Array.isArray(value) ? Boolean(value.find((v)=>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,
                    day: 1
                }
            };
        });
        if (eventList?.length || disabledList?.length || max || min) {
            const modifiedMonths = getDatesWithModifications({
                dates: months,
                type: CalendarState.Months,
                min,
                max,
                includeEdgeDates,
                eventList,
                disabledList
            });
            return getMatrix(modifiedMonths, 3);
        }
        return getMatrix(months, 3);
    }, [
        date,
        value,
        eventList,
        disabledList,
        max,
        min,
        locale
    ]);
