import { addDays } from '@astral/utils/date/addDays';
import { DAYS_IN_WEEK } from '../../../../../constants';
import { buildIsoDate, DAYS_CALENDAR_ITEMS_COUNT, } from '../../../../../utils/date';
/**
 * Утилита создающая крайние даты для основного диапазона
 */
export const makeEdgeDates = (baseDate, isMondayFirst) => {
    const month = baseDate.getUTCMonth() + 1;
    const optimizedBaseDate = buildIsoDate({
        year: baseDate.getUTCFullYear(),
        month,
    });
    const firstDayCompensate = isMondayFirst ? 0 : 1;
    const weekBaseDate = optimizedBaseDate.getUTCDay();
    /**
     * Количество дней от 1го числа месяца, до понедельника(первой даты пикера)
     */
    const offset = isMondayFirst && weekBaseDate === 0
        ? DAYS_IN_WEEK - 1
        : weekBaseDate + firstDayCompensate - 1;
    const addDayCount = offset * -1;
    const startDate = addDays(optimizedBaseDate, addDayCount);
    const endDate = addDays(startDate, DAYS_CALENDAR_ITEMS_COUNT - 1);
    return {
        startDate,
        endDate,
    };
};
