"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var registerCSSInterfaceWithDefaultTheme_1 = __importDefault(require("react-dates/lib/utils/registerCSSInterfaceWithDefaultTheme"));
var moment_1 = __importDefault(require("moment"));
var lodash_1 = __importDefault(require("lodash"));
registerCSSInterfaceWithDefaultTheme_1.default();
// need this to check control is blur when TAB key away
exports.isElementFocused = function (container) {
    var activeElement = document.activeElement;
    if (container === activeElement) {
        return true;
    }
    return activeElement && container ? container.contains(activeElement) : false;
};
exports.isSameDate = function (oldDate, newDate) {
    if (oldDate && newDate) {
        return moment_1.default(oldDate).isSame(newDate, 'date');
    }
    return !oldDate && !newDate;
};
function dateRangePickerValueFormatter(startDate, endDate) {
    if (exports.isSameDate(startDate, endDate)) {
        return startDate.format('L');
    }
    var formatDate = function (date) { return (date ? date.format('L') : null); };
    return formatDate(startDate) + " - " + formatDate(endDate);
}
exports.dateRangePickerValueFormatter = dateRangePickerValueFormatter;
exports.REACT_DATES_START_DATE_INPUT_MODE = 'startDate';
function is24HoursMode(timeFormat) {
    return /H/.test(timeFormat);
}
exports.is24HoursMode = is24HoursMode;
function getSiblingYearList(currentYear, yearBeforeCurrent, yearAfterCurrent) {
    return lodash_1.default.range(currentYear - yearAfterCurrent, currentYear + yearAfterCurrent);
}
exports.getSiblingYearList = getSiblingYearList;
function isActiveRange(_a) {
    var startDate = _a.startDate, endDate = _a.endDate, range = _a.range;
    if (!startDate || !endDate) {
        return false;
    }
    var rangeStart = range.startDate, rangeEnd = range.endDate;
    return exports.isSameDate(startDate, rangeStart) && exports.isSameDate(endDate, rangeEnd);
}
exports.isActiveRange = isActiveRange;
function parsePreDefinedRangeConfig(rangeConfig) {
    var range = lodash_1.default.clone(rangeConfig);
    if (lodash_1.default.isFunction(rangeConfig.startDate)) {
        range.startDate = rangeConfig.startDate(moment_1.default());
    }
    if (lodash_1.default.isFunction(rangeConfig.endDate)) {
        range.endDate = rangeConfig.endDate(moment_1.default());
    }
    return range;
}
exports.parsePreDefinedRangeConfig = parsePreDefinedRangeConfig;
//# sourceMappingURL=datePickerHelpers.js.map