"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonthOptions = getMonthOptions;
exports.getYearOptions = getYearOptions;
const date_fns_1 = require("date-fns");
/** Return the months to show in the dropdown. */
function getMonthOptions({ displayMonth, navStart, navEnd, locale, }) {
    const months = (0, date_fns_1.eachMonthOfInterval)({
        start: (0, date_fns_1.startOfYear)(displayMonth),
        end: (0, date_fns_1.endOfYear)(displayMonth),
    });
    const options = months.map((month) => {
        const label = (0, date_fns_1.format)(month, "LLLL", {
            locale,
        }).replace(".", "");
        const value = (0, date_fns_1.getMonth)(month);
        const disabled = (navStart && month < (0, date_fns_1.startOfMonth)(navStart)) ||
            (navEnd && month > (0, date_fns_1.startOfMonth)(navEnd)) ||
            false;
        return { value, label, disabled };
    });
    return options;
}
/** Return the years to show in the dropdown. */
function getYearOptions({ navStart, navEnd, locale, }) {
    if (!navStart)
        return undefined;
    if (!navEnd)
        return undefined;
    const firstNavYear = (0, date_fns_1.startOfYear)(navStart);
    const lastNavYear = (0, date_fns_1.endOfYear)(navEnd);
    const years = [];
    let year = firstNavYear;
    while ((0, date_fns_1.isBefore)(year, lastNavYear) || (0, date_fns_1.isSameYear)(year, lastNavYear)) {
        years.push(year);
        year = (0, date_fns_1.addYears)(year, 1);
    }
    return years.map((_year) => {
        const label = (0, date_fns_1.format)(_year, "yyyy", { locale });
        return {
            value: (0, date_fns_1.getYear)(_year),
            label,
            disabled: false,
        };
    });
}
//# sourceMappingURL=dropdown-options.js.map