"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "getFormattedDateTime", {
    enumerable: true,
    get: function() {
        return getFormattedDateTime;
    }
});
var _dateHelper = require("../../DatePicker/utils/dateHelper");
var _getOriginalDateTime = require("./getOriginalDateTime");
var _normalizeDateTime = require("./normalizeDateTime");
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
var getFormattedDateTime = function getFormattedDateTime(param) {
    var value = param.value, lang = param.lang, format = param.format, dateFormat = param.dateFormat, timeFormat = param.timeFormat, includeEdgeDates = param.includeEdgeDates, min = param.min, max = param.max;
    var withFullMonth = (0, _dateHelper.needFullMonth)(format || '');
    var _getOriginalDateTime1 = (0, _getOriginalDateTime.getOriginalDateTime)({
        value: value,
        lang: lang,
        fullFormat: format,
        dateFormat: dateFormat,
        timeFormat: timeFormat,
        needFullMonth: withFullMonth
    }), formattedDate = _getOriginalDateTime1.formattedDate, isoDate = _getOriginalDateTime1.isoDate, originalDate = _getOriginalDateTime1.originalDate, timeValue = _getOriginalDateTime1.timeValue, dateValue = _getOriginalDateTime1.dateValue;
    if (!originalDate) {
        var innerValue = format && ((0, _dateHelper.needFullMonth)(format) ? formattedDate : formattedDate.slice(0, format.length));
        var result = {
            formattedDate: innerValue || '',
            isoDate: isoDate,
            originalDate: originalDate,
            timeValue: timeValue,
            dateValue: dateValue
        };
        if (dateValue && !timeValue) {
            var _normalizeDateTime1 = (0, _normalizeDateTime.normalizeDateTime)({
                originalDate: dateValue,
                lang: lang,
                format: dateFormat,
                includeEdgeDates: includeEdgeDates,
                min: min,
                max: max
            }), normalizedDate = _normalizeDateTime1.normalizedDate, formattedNormalizedDate = _normalizeDateTime1.formattedNormalizedDate;
            var parsedNormalizedDate = formattedNormalizedDate + (innerValue === null || innerValue === void 0 ? void 0 : innerValue.slice(formattedNormalizedDate.length));
            return _object_spread_props(_object_spread({}, result), {
                formattedDate: parsedNormalizedDate,
                dateValue: normalizedDate
            });
        }
        return result;
    }
    var _normalizeDateTime2 = (0, _normalizeDateTime.normalizeDateTime)({
        originalDate: originalDate,
        lang: lang,
        format: format,
        includeEdgeDates: includeEdgeDates,
        min: min,
        max: max
    }), normalizedDate1 = _normalizeDateTime2.normalizedDate, formattedNormalizedDate1 = _normalizeDateTime2.formattedNormalizedDate;
    return {
        formattedDate: formattedNormalizedDate1,
        isoDate: normalizedDate1.toISOString(),
        originalDate: normalizedDate1,
        timeValue: normalizedDate1,
        dateValue: normalizedDate1
    };
};
