'use strict';

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

const setDateRangeValuesWithinMinMax = (filter, startValue, endValue) => {
    const { min, max } = filter;
    const start = min ? compareMin(min, startValue) : startValue;
    const end = max ? compareMax(max, endValue) : endValue;
    return {
        start: start || '',
        end: end || '',
    };
};
const compareMin = (min, dateValue) => {
    const minDate = new Date(min);
    const date = dateValue ? new Date(dateValue) : new Date();
    return date < minDate ? min : dateValue;
};
const compareMax = (max, dateValue) => {
    const maxDate = new Date(max);
    const date = dateValue ? new Date(dateValue) : new Date();
    return date > maxDate ? max : dateValue;
};
const getStartAndEndValueFromDefinition = (filter) => {
    const { min, max, defaultValue, defaultQuickFilterValue } = filter;
    let value = { start: '', end: '' };
    if (defaultQuickFilterValue) {
        value.relative = defaultQuickFilterValue;
    }
    else {
        let startValue;
        let endValue;
        if (min)
            startValue = min;
        if (max)
            endValue = max;
        const dateRegEx = /^\d{1,4}-\d{1,2}-\d{2,2} - \d{1,4}-\d{1,2}-\d{1,2}$/;
        if (defaultValue && defaultValue.match(dateRegEx)) {
            [startValue, endValue] = defaultValue.split(' - ');
            value = setDateRangeValuesWithinMinMax(filter, startValue, endValue);
        }
    }
    return value;
};
function isDateRange(value) {
    return value.start !== undefined || value.end !== undefined;
}
var StartEndDateUtils = {
    compareMax,
    compareMin,
    isDateRange,
    setDateRangeValuesWithinMinMax,
    getStartAndEndValueFromDefinition,
};

exports.compareMax = compareMax;
exports.compareMin = compareMin;
exports.default = StartEndDateUtils;
exports.getStartAndEndValueFromDefinition = getStartAndEndValueFromDefinition;
exports.isDateRange = isDateRange;
exports.setDateRangeValuesWithinMinMax = setDateRangeValuesWithinMinMax;
//# sourceMappingURL=utils.js.map
