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


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

var calculateMonth = function calculateMonth(month) {
  if (month <= 7) {
    return month + 1;
  }

  return month;
};

var getIsLeapYear = function getIsLeapYear(year) {
  // The year is considered leap if it's either dividable by 4, 100 or 400.
  var isDividableByFour = year % 4 === 0;
  var isDividableByOneHundred = year % 100 === 0;
  var isDividableByFourHundred = year % 400 === 0;

  return isDividableByFour || isDividableByOneHundred || isDividableByFourHundred;
};var

InternalDateGetter = exports.InternalDateGetter = /*#__PURE__*/function () {function InternalDateGetter() {}InternalDateGetter.






  getMaxDaysInMonth = function getMaxDaysInMonth(month, year) {
    if (month === 2) {
      var isLeapYear = year ? getIsLeapYear(year) : false;

      return isLeapYear ? 29 : 28;
    }

    var calculatedMonth = calculateMonth(month);
    return calculatedMonth % 2 === 0 ? 31 : 30;
  };InternalDateGetter.

  getValueDateComponent = function getValueDateComponent(
  type,
  components)
  {
    if (type === _types.InternalDateComponentType.Year) {
      return components.year;
    }

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

    return components.date;
  };InternalDateGetter.

  getDefaultMin = function getDefaultMin(type) {
    if (type === _types.InternalDateComponentType.Year) {
      return _constants.MIN_YEAR;
    } else if (type === _types.InternalDateComponentType.Month) {
      return _constants.MIN_MONTH;
    } else if (type === _types.InternalDateComponentType.Date) {
      return _constants.MIN_DATE;
    }
    return _constants.MIN_DATE;
  };InternalDateGetter.

  getDefaultMax = function getDefaultMax(
  type,
  components,
  dateInputAllowInvalidValuesInDays)
  {
    if (type === _types.InternalDateComponentType.Year) {
      return _constants.MAX_YEAR;
    } else if (type === _types.InternalDateComponentType.Month) {
      return _constants.MAX_MONTH;
    } else if (type === _types.InternalDateComponentType.Date) {
      if (dateInputAllowInvalidValuesInDays) {
        return _constants.MAX_DATE;
      }
      if (components === undefined) {
        return _constants.MAX_DATE;
      }
      var year = components.year,month = components.month;
      return year && month ? InternalDateGetter.getMaxDaysInMonth(month, year) : _constants.MAX_DATE;
    }
    return _constants.MAX_DATE;
  };InternalDateGetter.

  getTodayComponents = function getTodayComponents() {
    var date = new Date();
    return {
      date: date.getDate(),
      month: date.getMonth() + 1,
      year: date.getFullYear()
    };
  };return InternalDateGetter;}();InternalDateGetter.max = function (datesCustom) {return datesCustom.sort(function (a, b) {return b.toNumber() - a.toNumber();})[0];};InternalDateGetter.min = function (datesCustom) {return datesCustom.sort(function (a, b) {return a.toNumber() - b.toNumber();})[0];};