import { customDayjs } from '../../../utils/datejs.js';

var normalizeDateTime = function normalizeDateTime(_ref) {
  var originalDate = _ref.originalDate,
    lang = _ref.lang,
    format = _ref.format,
    includeEdgeDates = _ref.includeEdgeDates,
    min = _ref.min,
    max = _ref.max;
  var dateCandidate = originalDate;
  customDayjs.locale(lang);
  if (min && includeEdgeDates && min > originalDate) {
    dateCandidate = min;
  } else if (min && !includeEdgeDates && min >= originalDate) {
    dateCandidate = customDayjs(min).add(1, 's').toDate();
  } else if (max && includeEdgeDates && max < originalDate) {
    dateCandidate = max;
  } else if (max && !includeEdgeDates && max <= originalDate) {
    dateCandidate = customDayjs(max).subtract(1, 's').toDate();
  }
  var formattedDateCandidate = format ? customDayjs(dateCandidate).format(format) : dateCandidate.toString();
  return {
    normalizedDate: dateCandidate,
    formattedNormalizedDate: formattedDateCandidate
  };
};

export { normalizeDateTime };
