"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "useDays", {
    enumerable: true,
    get: function() {
        return useDays;
    }
});
const _react = require("react");
const _utils = require("../utils");
const _types = require("../store/types");
/**
 * Метод возвращающий массив дней в предыдущем месяце.
 */ const getDaysInPrevMonth = (date, offsetDayInWeek, value)=>{
    const [prevYear, prevMonth] = (0, _utils.getPrevDate)(date.year, date.monthIndex);
    const daysInPrevMonth = (0, _utils.getDaysInMonth)(prevMonth, prevYear);
    return Array.from(Array(offsetDayInWeek), (_, i)=>({
            isCurrent: false,
            isSelected: false,
            isDayInCurrentMonth: false,
            inRange: Array.isArray(value) ? (0, _utils.isDateInRange)(prevYear, prevMonth, daysInPrevMonth - (offsetDayInWeek - i) + 1, value) : false,
            date: {
                day: daysInPrevMonth - (offsetDayInWeek - i) + 1,
                monthIndex: prevMonth,
                year: prevYear
            }
        }));
};
/**
 * Метод возвращающий массив дней в текущем месяце.
 */ const getDaysInCurrentMonth = (date, daysInMonth, value)=>{
    return Array.from(Array(daysInMonth), (_, i)=>({
            isCurrent: (0, _utils.IsCurrentDay)(date, i + 1),
            isSelected: Array.isArray(value) ? Boolean(value.find((v)=>(0, _utils.isSelectedDay)(date, i + 1, v))) : (0, _utils.isSelectedDay)(date, i + 1, value),
            isDayInCurrentMonth: true,
            inRange: Array.isArray(value) ? (0, _utils.isDateInRange)(date.year, date.monthIndex, i + 1, value) : false,
            date: {
                day: i + 1,
                monthIndex: date.monthIndex,
                year: date.year
            }
        }));
};
/**
 * Метод возвращающий массив дней в следующем месяце.
 */ const getDaysInNextMonth = (date, daysInMonth, offsetDayInWeek, value)=>{
    const [nextYear, nextMonthIndex] = (0, _utils.getNextDate)(date.year, date.monthIndex);
    const visibleDayCount = 42;
    const restDaysInCalendar = visibleDayCount - (daysInMonth + offsetDayInWeek);
    return Array.from(Array(restDaysInCalendar), (_, i)=>({
            isCurrent: false,
            isSelected: false,
            isDayInCurrentMonth: false,
            inRange: Array.isArray(value) ? (0, _utils.isDateInRange)(nextYear, nextMonthIndex, i + 1, value) : false,
            date: {
                day: i + 1,
                monthIndex: nextMonthIndex,
                year: nextYear
            }
        }));
};
const useDays = ({ date, value, eventList, disabledList, min, max, includeEdgeDates })=>(0, _react.useMemo)(()=>{
        const { monthIndex, year } = date;
        const daysInMonth = (0, _utils.getDaysInMonth)(monthIndex, year);
        const offsetDayInWeek = (0, _utils.getOffsetDayInWeek)(monthIndex, year);
        const days = [
            ...getDaysInPrevMonth(date, offsetDayInWeek, value),
            ...getDaysInCurrentMonth(date, daysInMonth, value),
            ...getDaysInNextMonth(date, daysInMonth, offsetDayInWeek, value)
        ];
        if (eventList?.length || disabledList?.length || max || min) {
            const modifiedDays = (0, _utils.getDatesWithModifications)({
                dates: days,
                type: _types.CalendarState.Days,
                includeEdgeDates,
                min,
                max,
                eventList,
                disabledList
            });
            return (0, _utils.getMatrix)(modifiedDays);
        }
        return (0, _utils.getMatrix)(days);
    }, [
        date,
        value,
        eventList,
        disabledList,
        max,
        min,
        includeEdgeDates
    ]);
