"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useYearsGrid = void 0;
const react_1 = require("react");
const date_1 = require("../../../../utils/date");
const MinMaxDateContext_1 = require("../../../MinMaxDateContext");
const constants_1 = require("../../constants");
// отступ означающий на сколько нужно сделать отступ в годовом календаре, чтобы опорный год отрендерился в указанном месте
// если делать без него, то опорный год будет отрендерен в самом начале списка
const YEAR_OFFSET = 4;
const useYearsGrid = ({ baseDate, selectedDate, selectedRanges, }) => {
    const { maxDate, minDate } = (0, react_1.useContext)(MinMaxDateContext_1.MinMaxDateContext);
    return (0, react_1.useMemo)(() => {
        const grid = [];
        const baseYear = baseDate.getUTCFullYear();
        const currentYear = new Date().getFullYear();
        const selectedYear = selectedDate?.getUTCFullYear();
        for (let i = 0 - YEAR_OFFSET; i < constants_1.YEARS_IN_GRID - YEAR_OFFSET; i++) {
            const date = (0, date_1.buildIsoDate)({ year: baseYear + i });
            const year = date.getUTCFullYear();
            grid.push({
                date,
                year,
                isSelected: selectedYear === year,
                isCurrentInUserLocalTime: year === currentYear,
                isInSelectedRange: selectedRanges?.some(({ dateA, dateB }) => (0, date_1.checkIsDateInRange)({
                    date,
                    dateA,
                    dateB,
                    deep: date_1.DateCompareDeep.Year,
                })) ?? false,
                isDisabled: (0, date_1.isDateOutOfRange)({
                    date,
                    dateA: minDate,
                    dateB: maxDate,
                    deep: date_1.DateCompareDeep.Year,
                }),
            });
        }
        return grid;
    }, [baseDate, selectedDate, maxDate, minDate, selectedRanges]);
};
exports.useYearsGrid = useYearsGrid;
