'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
var dateHelper = require('../../DatePicker/utils/dateHelper.js');
var getOriginalDateTime = require('./getOriginalDateTime.js');
var normalizeDateTime = require('./normalizeDateTime.js');

var getFormattedDateTime = function getFormattedDateTime(_ref) {
  var value = _ref.value,
    lang = _ref.lang,
    format = _ref.format,
    dateFormat = _ref.dateFormat,
    timeFormat = _ref.timeFormat,
    includeEdgeDates = _ref.includeEdgeDates,
    min = _ref.min,
    max = _ref.max;
  var withFullMonth = dateHelper.needFullMonth(format || '');
  var _getOriginalDateTime = getOriginalDateTime.getOriginalDateTime({
      value: value,
      lang: lang,
      fullFormat: format,
      dateFormat: dateFormat,
      timeFormat: timeFormat,
      needFullMonth: withFullMonth
    }),
    formattedDate = _getOriginalDateTime.formattedDate,
    isoDate = _getOriginalDateTime.isoDate,
    originalDate = _getOriginalDateTime.originalDate,
    timeValue = _getOriginalDateTime.timeValue,
    dateValue = _getOriginalDateTime.dateValue;
  if (!originalDate) {
    var innerValue = format && (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 _normalizeDateTime = normalizeDateTime.normalizeDateTime({
          originalDate: dateValue,
          lang: lang,
          format: dateFormat,
          includeEdgeDates: includeEdgeDates,
          min: min,
          max: max
        }),
        _normalizedDate = _normalizeDateTime.normalizedDate,
        _formattedNormalizedDate = _normalizeDateTime.formattedNormalizedDate;
      var parsedNormalizedDate = _formattedNormalizedDate + (innerValue === null || innerValue === void 0 ? void 0 : innerValue.slice(_formattedNormalizedDate.length));
      return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
        formattedDate: parsedNormalizedDate,
        dateValue: _normalizedDate
      });
    }
    return result;
  }
  var _normalizeDateTime2 = normalizeDateTime.normalizeDateTime({
      originalDate: originalDate,
      lang: lang,
      format: format,
      includeEdgeDates: includeEdgeDates,
      min: min,
      max: max
    }),
    normalizedDate = _normalizeDateTime2.normalizedDate,
    formattedNormalizedDate = _normalizeDateTime2.formattedNormalizedDate;
  return {
    formattedDate: formattedNormalizedDate,
    isoDate: normalizedDate.toISOString(),
    originalDate: normalizedDate,
    timeValue: normalizedDate,
    dateValue: normalizedDate
  };
};

exports.getFormattedDateTime = getFormattedDateTime;
