'use strict';

var dayjs = require('dayjs');
var isBetween = require('../../_virtual/isBetween.js');
var types = require('../components/_inputs/date-range/types.js');

dayjs.extend(isBetween);
const RANGE_CALCULATORS = {
    [types.default.YESTERDAY]: (now) => ({
        startDate: now.subtract(1, 'day'),
        endDate: now,
    }),
    [types.default.TOMORROW]: (now) => ({
        startDate: now,
        endDate: now.add(1, 'day'),
    }),
    [types.default.LAST_WEEK]: (now) => ({
        startDate: now.subtract(1, 'week'),
        endDate: now,
    }),
    [types.default.NEXT_WEEK]: (now) => ({
        startDate: now,
        endDate: now.add(1, 'week'),
    }),
    [types.default.LAST_MONTH]: (now) => ({
        startDate: now.subtract(1, 'month'),
        endDate: now,
    }),
    [types.default.NEXT_MONTH]: (now) => ({
        startDate: now,
        endDate: now.add(1, 'month'),
    }),
};
const calcDatesInternal = (range) => {
    const now = dayjs().startOf('day');
    return RANGE_CALCULATORS[range](now);
};
const calcDates = (range) => {
    if (range === types.default.NONE) {
        return null;
    }
    return calcDatesInternal(range);
};
/* -----------------------------------------
/* ADAPTERS
/* -----------------------------------------

/**
 * Adapter for date inputs (DD/MM/YYYY)
 */
const calcDatesForUI = (range) => {
    const result = calcDates(range);
    if (!result)
        return null;
    return {
        start: result.startDate.format('DD/MM/YYYY'),
        end: result.endDate.format('DD/MM/YYYY'),
    };
};
/**
 * Adapter for filter definitions (YYYY-MM-DD)
 */
const calcDatesForAPI = (range) => {
    const result = calcDates(range);
    if (!result)
        return null;
    return {
        start: result.startDate.format('YYYY-MM-DD'),
        end: result.endDate.format('YYYY-MM-DD'),
    };
};

exports.calcDates = calcDates;
exports.calcDatesForAPI = calcDatesForAPI;
exports.calcDatesForUI = calcDatesForUI;
//# sourceMappingURL=durationCalculator.js.map
