"use strict";exports.__esModule = true;exports.InternalDateValidator = void 0;
var _InternalDateGetter = require("./InternalDateGetter");

var _types = require("./types");
var _InternalDateTransformer = require("./InternalDateTransformer");

var calculateStartDate = function calculateStartDate(startDate) {
  if (startDate) {
    return startDate;
  }

  return -Infinity;
};

var calculateEndDate = function calculateEndDate(endDate) {
  if (endDate) {
    return endDate;
  }

  return Infinity;
};

var getValue = function getValue(type, _ref) {var year = _ref.year,month = _ref.month,date = _ref.date;
  if (type === _types.InternalDateComponentType.Year) {
    return year;
  }

  if (type === _types.InternalDateComponentType.Month) {
    return month;
  }

  return date;
};var

InternalDateValidator = exports.InternalDateValidator = /*#__PURE__*/function () {function InternalDateValidator() {}InternalDateValidator.
  checkForNull = function checkForNull(_ref2, type) {var year = _ref2.year,month = _ref2.month,date = _ref2.date;
    if (type !== undefined) {
      if (type === _types.InternalDateComponentType.Year) {
        return year !== null;
      }

      if (type === _types.InternalDateComponentType.Month) {
        return month !== null;
      }

      if (type === _types.InternalDateComponentType.All) {
        return year !== null && month !== null && date !== null;
      }

      return date !== null;
    }

    return !(year === null || month === null || date === null);
  };InternalDateValidator.

  checkLimits = function checkLimits(_ref3,

  type)
  {var year = _ref3.year,month = _ref3.month,date = _ref3.date;
    if (type !== undefined) {
      var value = getValue(type, { date: date, month: month, year: year });

      return value >= _InternalDateGetter.InternalDateGetter.getDefaultMin(type) && value <= _InternalDateGetter.InternalDateGetter.getDefaultMax(type);
    }

    return (
      year >= _InternalDateGetter.InternalDateGetter.getDefaultMin(_types.InternalDateComponentType.Year) &&
      year <= _InternalDateGetter.InternalDateGetter.getDefaultMax(_types.InternalDateComponentType.Year) &&
      month >= _InternalDateGetter.InternalDateGetter.getDefaultMin(_types.InternalDateComponentType.Month) &&
      month <= _InternalDateGetter.InternalDateGetter.getDefaultMax(_types.InternalDateComponentType.Month) &&
      date >= _InternalDateGetter.InternalDateGetter.getDefaultMin(_types.InternalDateComponentType.Date) &&
      date <= _InternalDateGetter.InternalDateGetter.getDefaultMax(_types.InternalDateComponentType.Date));

  };InternalDateValidator.

  compareWithNativeDate = function compareWithNativeDate(_ref4) {var year = _ref4.year,month = _ref4.month,date = _ref4.date;
    var nativeDate = _InternalDateTransformer.InternalDateTransformer.componentsToNativeDate({ year: year, month: month, date: date });
    return (
      nativeDate.getUTCFullYear() === year && nativeDate.getUTCMonth() + 1 === month && nativeDate.getUTCDate() === date);

  };InternalDateValidator.

  checkRangeFully = function checkRangeFully(date, startDate, endDate) {
    if (startDate === null && endDate === null) {
      return true;
    }

    var calculatedEndDate = calculateEndDate(endDate);
    var calculatedStartDate = calculateStartDate(startDate);
    return date >= calculatedStartDate && date <= calculatedEndDate;
  };InternalDateValidator.

  checkRangePiecemeal = function checkRangePiecemeal(
  type, _ref5,

  startComponents,
  endComponents)
  {var year = _ref5.year,month = _ref5.month,date = _ref5.date;
    if (startComponents === null && endComponents === null) {
      return true;
    }
    var _ref6 =



      startComponents || {},_ref6$year = _ref6.year,startYear = _ref6$year === void 0 ? -Infinity : _ref6$year,_ref6$month = _ref6.month,startMonth = _ref6$month === void 0 ? -Infinity : _ref6$month,_ref6$date = _ref6.date,startDate = _ref6$date === void 0 ? -Infinity : _ref6$date;
    var _ref7 = endComponents || {},_ref7$year = _ref7.year,endYear = _ref7$year === void 0 ? Infinity : _ref7$year,_ref7$month = _ref7.month,endMonth = _ref7$month === void 0 ? Infinity : _ref7$month,_ref7$date = _ref7.date,endDate = _ref7$date === void 0 ? Infinity : _ref7$date;

    if (type === _types.InternalDateComponentType.Year) {
      return !(year < startYear || year > endYear);
    } else if (type === _types.InternalDateComponentType.Month) {
      return !(year === startYear && month < startMonth || year === endYear && month > endMonth);
    } else if (type === _types.InternalDateComponentType.Date) {
      return !(
      year === startYear && month === startMonth && date < startDate ||
      year === endYear && month === endMonth && date > endDate);

    }
    return true;
  };InternalDateValidator.

  testParseToNumber = function testParseToNumber(value) {
    if (value !== null) {
      return typeof value === 'number' || !Number.isNaN(parseInt(value, 10));
    }

    return false;
  };InternalDateValidator.

  isEqualDateValues = function isEqualDateValues(a, b) {
    return a.toInternalString() === b.toInternalString();
  };InternalDateValidator.

  isEqualDateFormats = function isEqualDateFormats(a, b) {
    var areOrdersEqual = a.getOrder() === b.getOrder();
    var areSeparatorsEqual = a.getSeparator() === b.getSeparator();

    return areOrdersEqual && areSeparatorsEqual;
  };return InternalDateValidator;}();