import _extends from "@babel/runtime/helpers/esm/extends";
import { InternalDateOrder, InternalDateSeparator, InternalDateValidateCheck } from "../../../../lib/date/types";
import { InternalDate } from "../../../../lib/date/InternalDate";
import { MAX_FULLDATE, MIN_FULLDATE } from "../../../../lib/date/constants";
import { isLessOrEqual } from "../../../../lib/date/comparison";
var defaultOptions = {
  startOptional: false,
  endOptional: false,
  minDate: MIN_FULLDATE,
  maxDate: MAX_FULLDATE
};
export function validateDateRangePicker(startValue, endValue, options) {
  if (options === void 0) {
    options = defaultOptions;
  }
  var _defaultOptions$optio = _extends({}, defaultOptions, options),
    startOptional = _defaultOptions$optio.startOptional,
    endOptional = _defaultOptions$optio.endOptional,
    minDate = _defaultOptions$optio.minDate,
    maxDate = _defaultOptions$optio.maxDate;
  var isStartEmpty = !startValue;
  var isStartRequired = !startOptional;
  var isEndEmpty = !endValue;
  var isEndRequired = !endOptional;
  if (!isStartEmpty && !isEndEmpty && !isRangeValid(startValue, endValue)) {
    return [false, false];
  }
  var internalDate = getInternalDate(minDate, maxDate);
  var isStartValid = isStartEmpty ? !isStartRequired : checkDate(internalDate.parseValue(startValue));
  var isEndValid = isEndEmpty ? !isEndRequired : checkDate(internalDate.parseValue(endValue));
  return [isStartValid, isEndValid];
}
function isRangeValid(startValue, endValue) {
  return isLessOrEqual(startValue || '', endValue || '');
}
function getInternalDate(minDate, maxDate) {
  return new InternalDate({
    order: InternalDateOrder.DMY,
    separator: InternalDateSeparator.Dot
  }).setRangeStart(new InternalDate({
    value: minDate
  })).setRangeEnd(new InternalDate({
    value: maxDate
  }));
}
function checkDate(internalDate) {
  return internalDate.validate({
    checks: [InternalDateValidateCheck.NotNull, InternalDateValidateCheck.Number, InternalDateValidateCheck.Native, InternalDateValidateCheck.Limits, InternalDateValidateCheck.Range]
  });
}