"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.validateDateRangePicker = validateDateRangePicker;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _types = require("../../../lib/date/types");
var _InternalDate = require("../../../lib/date/InternalDate");
var _constants = require("../../../lib/date/constants");
var _comparison = require("../../../lib/date/comparison");









var defaultOptions = {
  startOptional: false,
  endOptional: false,
  minDate: _constants.MIN_FULLDATE,
  maxDate: _constants.MAX_FULLDATE
};

function validateDateRangePicker(
startValue,
endValue,
options)
{if (options === void 0) {options = defaultOptions;}
  var _defaultOptions$optio = (0, _extends2.default)({}, 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 (0, _comparison.isLessOrEqual)(startValue || '', endValue || '');
}

function getInternalDate(minDate, maxDate) {
  return new _InternalDate.InternalDate({
    order: _types.InternalDateOrder.DMY,
    separator: _types.InternalDateSeparator.Dot
  }).
  setRangeStart(new _InternalDate.InternalDate({ value: minDate })).
  setRangeEnd(new _InternalDate.InternalDate({ value: maxDate }));
}

function checkDate(internalDate) {
  return internalDate.validate({
    checks: [
    _types.InternalDateValidateCheck.NotNull,
    _types.InternalDateValidateCheck.Number,
    _types.InternalDateValidateCheck.Native,
    _types.InternalDateValidateCheck.Limits,
    _types.InternalDateValidateCheck.Range]

  });
}