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 _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
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;
}
import { customDayjs } from "../../../utils/datejs";
var initialValueStructure = {
    isoDate: '',
    originalDate: undefined,
    dateValue: undefined,
    timeValue: undefined,
    formattedDate: ''
};
export var getOriginalDateTime = function getOriginalDateTime(param) {
    var value = param.value, lang = param.lang, fullFormat = param.fullFormat, dateFormat = param.dateFormat, timeFormat = param.timeFormat, needFullMonth = param.needFullMonth;
    var _String;
    if (!value || !lang || !fullFormat) {
        return initialValueStructure;
    }
    customDayjs.locale(lang);
    if (_instanceof(value, Date)) {
        var currentDate = new Date(value);
        return {
            formattedDate: customDayjs(value).format(fullFormat),
            isoDate: currentDate.toISOString(),
            originalDate: currentDate,
            dateValue: currentDate,
            timeValue: currentDate
        };
    }
    if (!needFullMonth && fullFormat.length !== ((_String = String(value)) === null || _String === void 0 ? void 0 : _String.length)) {
        var baseValueStructure = _object_spread_props(_object_spread({}, initialValueStructure), {
            formattedDate: value
        });
        var rawDate = value.slice(0, dateFormat === null || dateFormat === void 0 ? void 0 : dateFormat.length);
        var rawTime = value.slice(((dateFormat === null || dateFormat === void 0 ? void 0 : dateFormat.length) || 0) + 1);
        if (dateFormat && customDayjs(rawDate, dateFormat, true).isValid()) {
            baseValueStructure = _object_spread_props(_object_spread({}, baseValueStructure), {
                dateValue: customDayjs(rawDate, dateFormat).toDate()
            });
        }
        if (timeFormat && customDayjs(rawTime, timeFormat, true).isValid()) {
            baseValueStructure = _object_spread_props(_object_spread({}, baseValueStructure), {
                timeValue: customDayjs(value, fullFormat).toDate()
            });
        }
        return baseValueStructure;
    }
    if (customDayjs(value, fullFormat).isValid()) {
        var isoDate = customDayjs(value, fullFormat).toISOString();
        var originalDate = customDayjs(value, fullFormat).toDate();
        var formattedDate = customDayjs(value, fullFormat).format(fullFormat);
        return {
            formattedDate: formattedDate,
            isoDate: isoDate,
            originalDate: originalDate,
            dateValue: originalDate,
            timeValue: originalDate
        };
    }
    return _object_spread_props(_object_spread({}, initialValueStructure), {
        formattedDate: value
    });
};
