import { objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { customDayjs } from '../../../utils/datejs.js';

var initialValueStructure = {
  isoDate: '',
  originalDate: undefined,
  dateValue: undefined,
  timeValue: undefined,
  formattedDate: ''
};
var getOriginalDateTime = function getOriginalDateTime(_ref) {
  var _String;
  var value = _ref.value,
    lang = _ref.lang,
    fullFormat = _ref.fullFormat,
    dateFormat = _ref.dateFormat,
    timeFormat = _ref.timeFormat,
    needFullMonth = _ref.needFullMonth;
  if (!value || !lang || !fullFormat) {
    return initialValueStructure;
  }
  customDayjs.locale(lang);
  if (value instanceof 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 = _objectSpread2(_objectSpread2({}, 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 = _objectSpread2(_objectSpread2({}, baseValueStructure), {}, {
        dateValue: customDayjs(rawDate, dateFormat).toDate()
      });
    }
    if (timeFormat && customDayjs(rawTime, timeFormat, true).isValid()) {
      baseValueStructure = _objectSpread2(_objectSpread2({}, 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 _objectSpread2(_objectSpread2({}, initialValueStructure), {}, {
    formattedDate: value
  });
};

export { getOriginalDateTime };
