'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var utils = require('./components/calendar/utils.js');
var dateUtils = require('./dateUtils.js');

const today = new Date();
const yesterday = dateUtils.subDays(today, 1);
const prevMonth = utils.getPrevMonth(today.getMonth());
const year = prevMonth === 11 ? today.getFullYear() - 1 : today.getFullYear();
const firstDay = dateUtils.getFirstDayOfMonth(year, prevMonth);
const lastDay = dateUtils.getLastDayOfMonth(year, prevMonth);
const CommonSelectorValue = {
    today: 'TODAY',
    yesterday: 'YESTERDAY',
    last7Days: 'LASTSEVEN',
    last28Days: 'LASTTWENTYEIGHT',
    lastMonth: 'LASTMONTH',
    custom: 'CUSTOM',
};
const commonDateSelector = {
    [CommonSelectorValue.today]: {
        label: 'Today',
        value: CommonSelectorValue.today,
        dateRange: today,
    },
    [CommonSelectorValue.yesterday]: {
        label: 'Yesterday',
        value: CommonSelectorValue.yesterday,
        dateRange: yesterday,
    },
    [CommonSelectorValue.last7Days]: {
        label: 'Last 7 Days',
        value: CommonSelectorValue.last7Days,
        dateRange: { start: dateUtils.subDays(yesterday, 6), end: yesterday },
    },
    [CommonSelectorValue.last28Days]: {
        label: 'Last 28 Days',
        value: CommonSelectorValue.last28Days,
        dateRange: { start: dateUtils.subDays(yesterday, 27), end: yesterday },
    },
    [CommonSelectorValue.lastMonth]: {
        label: 'Last Month',
        value: CommonSelectorValue.lastMonth,
        dateRange: { start: firstDay, end: lastDay },
    },
};
const commonDateSelectors = [
    commonDateSelector[CommonSelectorValue.today],
    commonDateSelector[CommonSelectorValue.yesterday],
    commonDateSelector[CommonSelectorValue.last7Days],
    commonDateSelector[CommonSelectorValue.last28Days],
    commonDateSelector[CommonSelectorValue.lastMonth],
];
const getSelectors = (selectors = []) => {
    var _a;
    const customSelector = (_a = selectors.find((s) => s.value === CommonSelectorValue.custom)) !== null && _a !== void 0 ? _a : {
        label: 'Custom',
        value: CommonSelectorValue.custom,
    };
    return [
        ...selectors.filter(({ value }) => value !== CommonSelectorValue.custom),
        customSelector,
    ];
};
const shouldUseSelectorsProp = (selectors = []) => selectors.length > 1;
const popperOptions = {
    placement: 'bottom-start',
    modifiers: [
        {
            name: 'offset',
            options: {
                offset: [0, 2],
            },
        },
        {
            name: 'preventOverflow',
            options: {
                altAxis: true,
            },
        },
    ],
};
function getInitialMonths(month, year) {
    return [
        {
            month: utils.getPrevMonth(month),
            year: utils.getPrevYear(month, year),
        },
        {
            month: month,
            year: year,
        },
        {
            month: utils.getNextMonth(month),
            year: utils.getNextYear(month, year),
        },
    ];
}
function getCurrentMonth(currentDate, selectedRange) {
    if (selectedRange) {
        if (selectedRange instanceof Date) {
            return selectedRange.getMonth();
        }
        return selectedRange.start.getMonth();
    }
    return currentDate.getMonth();
}
function formatInputValue(dateRange, locale, variant, defaultRange) {
    const isSameDay = defaultRange
        ? dateUtils.getIsSameDay(defaultRange.start, defaultRange.end)
        : dateUtils.getIsSameDay(dateRange.start, dateRange.end);
    if (isSameDay) {
        const dateString = dateUtils.formatDate(dateRange.start, locale, variant);
        return dateString;
    }
    const start = dateUtils.formatDate(dateRange.start, locale, variant);
    const end = dateUtils.formatDate(dateRange.end, locale, variant);
    return `${start} - ${end}`;
}
const JS_MONTHS = {
    January: 0,
    December: 11,
};

exports.CommonSelectorValue = CommonSelectorValue;
exports.JS_MONTHS = JS_MONTHS;
exports.commonDateSelector = commonDateSelector;
exports.commonDateSelectors = commonDateSelectors;
exports.formatInputValue = formatInputValue;
exports.getCurrentMonth = getCurrentMonth;
exports.getInitialMonths = getInitialMonths;
exports.getSelectors = getSelectors;
exports.popperOptions = popperOptions;
exports.prevMonth = prevMonth;
exports.shouldUseSelectorsProp = shouldUseSelectorsProp;
exports.year = year;
