"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeEdgeDates = void 0;
const addDays_1 = require("@astral/utils/date/addDays");
const constants_1 = require("../../../../../constants");
const date_1 = require("../../../../../utils/date");
/**
 * Утилита создающая крайние даты для основного диапазона
 */
const makeEdgeDates = (baseDate, isMondayFirst) => {
    const month = baseDate.getUTCMonth() + 1;
    const optimizedBaseDate = (0, date_1.buildIsoDate)({
        year: baseDate.getUTCFullYear(),
        month,
    });
    const firstDayCompensate = isMondayFirst ? 0 : 1;
    const weekBaseDate = optimizedBaseDate.getUTCDay();
    /**
     * Количество дней от 1го числа месяца, до понедельника(первой даты пикера)
     */
    const offset = isMondayFirst && weekBaseDate === 0
        ? constants_1.DAYS_IN_WEEK - 1
        : weekBaseDate + firstDayCompensate - 1;
    const addDayCount = offset * -1;
    const startDate = (0, addDays_1.addDays)(optimizedBaseDate, addDayCount);
    const endDate = (0, addDays_1.addDays)(startDate, date_1.DAYS_CALENDAR_ITEMS_COUNT - 1);
    return {
        startDate,
        endDate,
    };
};
exports.makeEdgeDates = makeEdgeDates;
