var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { translate } from '../../../utils';
import { DayRangePicker } from './DateTimePicker/DayRangePicker';
import lang from '../../../lang/common/index-en_US';
var DateRangePickerWithPresets = /** @class */ (function (_super) {
    __extends(DateRangePickerWithPresets, _super);
    function DateRangePickerWithPresets() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.getRanges = function () {
            var _a;
            var _b = _this.props, todayText = _b.todayText, yesterdayText = _b.yesterdayText, days7Text = _b.days7Text, days30Text = _b.days30Text, days60Text = _b.days60Text;
            var _c = _this.getLocalTime(), NOW = _c.NOW, START_OF_YESTERDAY = _c.START_OF_YESTERDAY, START_OF_7_DAYS_AGO = _c.START_OF_7_DAYS_AGO, START_OF_30_DAYS_AGO = _c.START_OF_30_DAYS_AGO, START_OF_60_DAYS_AGO = _c.START_OF_60_DAYS_AGO;
            return _a = {},
                _a[todayText] = {
                    startDate: NOW,
                    endDate: NOW
                },
                _a[yesterdayText] = {
                    startDate: START_OF_YESTERDAY,
                    endDate: START_OF_YESTERDAY
                },
                _a[days7Text] = {
                    startDate: START_OF_7_DAYS_AGO,
                    endDate: NOW
                },
                _a[days30Text] = {
                    startDate: START_OF_30_DAYS_AGO,
                    endDate: NOW
                },
                _a[days60Text] = {
                    startDate: START_OF_60_DAYS_AGO,
                    endDate: NOW
                },
                _a;
        };
        _this.defaultValueFormatter = function (startDate, endDate) {
            var _a = _this.props, days7Text = _a.days7Text, days30Text = _a.days30Text, days60Text = _a.days60Text, todayDateText = _a.todayDateText, yesterdayDateText = _a.yesterdayDateText;
            var currentDate = _this.getCurrentDate();
            var isSelectOneDay = startDate.isSame(endDate, 'date');
            var isStartDateToday = startDate.isSame(currentDate, 'day');
            var isStartDateYesterday = startDate
                .clone()
                .add(1, 'day')
                .isSame(currentDate, 'day');
            var checkHowManyLastDaysSelected = function (daysAgo) {
                return _this.checkRangeDate({
                    startDate: startDate,
                    endDate: endDate,
                    daysAgo: daysAgo,
                    endRange: currentDate
                });
            };
            var longDateFormat = moment.localeData().longDateFormat('L');
            var formattedStartDate = startDate.format(longDateFormat);
            var formattedEndDate = endDate.format(longDateFormat);
            if (isSelectOneDay) {
                if (isStartDateToday) {
                    return translate(todayDateText, { date: formattedStartDate });
                }
                if (isStartDateYesterday) {
                    return translate(yesterdayDateText, { date: formattedStartDate });
                }
                return startDate.format('L');
            }
            if (checkHowManyLastDaysSelected(6)) {
                return days7Text;
            }
            if (checkHowManyLastDaysSelected(29)) {
                return days30Text;
            }
            if (checkHowManyLastDaysSelected(59)) {
                return days60Text;
            }
            return formattedStartDate + " - " + formattedEndDate;
        };
        return _this;
    }
    DateRangePickerWithPresets.prototype.getCurrentDate = function () {
        return moment.utc().zone(this.props.timeZoneOffset);
    };
    DateRangePickerWithPresets.prototype.getLocalTime = function () {
        return {
            NOW: this.getCurrentDate(),
            START_OF_TODAY: this.getCurrentDate(),
            START_OF_YESTERDAY: this.getCurrentDate().add(-1, 'days'),
            START_OF_7_DAYS_AGO: this.getCurrentDate().add(-6, 'days'),
            START_OF_30_DAYS_AGO: this.getCurrentDate().add(-29, 'days'),
            START_OF_60_DAYS_AGO: this.getCurrentDate().add(-59, 'days')
        };
    };
    DateRangePickerWithPresets.prototype.checkRangeDate = function (_a) {
        var startDate = _a.startDate, endDate = _a.endDate, daysAgo = _a.daysAgo, endRange = _a.endRange;
        return (startDate
            .clone()
            .add(daysAgo, 'day')
            .isSame(endDate, 'day') && endDate.isSame(endRange, 'day'));
    };
    DateRangePickerWithPresets.prototype.getValueFormatter = function () {
        if (this.props.useDefaultValueFormatter) {
            return this.defaultValueFormatter;
        }
        return this.props.valueFormatter;
    };
    DateRangePickerWithPresets.prototype.render = function () {
        var _a = this.props, timeZoneOffset = _a.timeZoneOffset, useDefaultValueFormatter = _a.useDefaultValueFormatter, valueFormatter = _a.valueFormatter, props = __rest(_a, ["timeZoneOffset", "useDefaultValueFormatter", "valueFormatter"]);
        return (React.createElement(DayRangePicker, __assign({}, props, { ranges: this.getRanges(), valueFormatter: this.getValueFormatter() })));
    };
    DateRangePickerWithPresets.propTypes = __assign({}, DayRangePicker.propTypes, { timeZoneOffset: PropTypes.number, useDefaultValueFormatter: PropTypes.bool, todayText: PropTypes.string, todayDateText: PropTypes.string, yesterdayText: PropTypes.string, yesterdayDateText: PropTypes.string, days7Text: PropTypes.string, days30Text: PropTypes.string, days60Text: PropTypes.string, days90Text: PropTypes.string, rangeText: PropTypes.string });
    DateRangePickerWithPresets.defaultProps = {
        useDefaultValueFormatter: true,
        get todayText() {
            return lang.TODAY;
        },
        get todayDateText() {
            return lang.TODAY_DATE;
        },
        get yesterdayText() {
            return lang.YESTERDAY;
        },
        get yesterdayDateText() {
            return lang.YESTERDAY_DATE;
        },
        get days7Text() {
            return lang.DAYS7;
        },
        get days30Text() {
            return lang.DAYS30;
        },
        get days60Text() {
            return lang.DAYS60;
        },
        get days90Text() {
            return lang.DAYS90;
        },
        get rangeText() {
            return lang.RANGE;
        },
        timeZoneOffset: 0
    };
    return DateRangePickerWithPresets;
}(React.PureComponent));
export { DateRangePickerWithPresets };
//# sourceMappingURL=DateRangePickerWithPresets.js.map