"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMonthsGrid = void 0;
const react_1 = require("react");
const constants_1 = require("../../../../constants");
const date_1 = require("../../../../utils/date");
const MinMaxDateContext_1 = require("../../../MinMaxDateContext");
const useMonthsGrid = ({ baseDate, selectedDate, selectedRanges, }) => {
    const { maxDate, minDate } = (0, react_1.useContext)(MinMaxDateContext_1.MinMaxDateContext);
    return (0, react_1.useMemo)(() => {
        const grid = [];
        const startDate = (0, date_1.buildIsoDate)({ year: baseDate.getUTCFullYear() });
        const year = startDate.getUTCFullYear();
        const currentDate = new Date();
        const currentMonth = currentDate.getMonth();
        const currentYear = currentDate.getFullYear();
        const selectedMonth = selectedDate?.getUTCMonth();
        const selectedYear = selectedDate?.getUTCFullYear();
        for (let i = 0; i < constants_1.MONTHS_IN_YEAR; i++) {
            const date = (0, date_1.buildIsoDate)({ year, month: i + 1 });
            grid.push({
                date,
                isSelected: selectedMonth === i && selectedYear === year,
                month: i + 1,
                isCurrentInUserLocalTime: i === currentMonth && year === currentYear,
                isInSelectedRange: selectedRanges?.some(({ dateA, dateB }) => (0, date_1.checkIsDateInRange)({
                    date,
                    dateA,
                    dateB,
                    deep: date_1.DateCompareDeep.Month,
                })) ?? false,
                isDisabled: (0, date_1.isDateOutOfRange)({
                    date,
                    dateA: minDate,
                    dateB: maxDate,
                    deep: date_1.DateCompareDeep.Month,
                }),
            });
        }
        return grid;
    }, [baseDate, selectedDate, maxDate, minDate, selectedRanges]);
};
exports.useMonthsGrid = useMonthsGrid;
