"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.calcMinStay = void 0;
var _locale = require("@mirai/locale");
var _Core = require("../../../../../Core.constants");
var _helpers = require("../../../../helpers");
const MAX_DAYS = 30;
const calcMinStay = function () {
  let {
    from,
    to,
    minStayDates,
    minStayType,
    rangeMinDays
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (to || !from || minStayType === undefined || !minStayDates) return rangeMinDays;
  let value = minStayDates[(0, _locale.dateFormat)(from, {
    format: _helpers.CALENDAR_FORMAT
  })];
  if (minStayType === _Core.MIN_STAY_TYPE.CHECK_IN || value === 1) return value;
  for (let index = 0; index < value; index++) {
    const current = minStayDates[(0, _locale.dateFormat)((0, _locale.dateCalc)(from, index) || from, {
      format: _helpers.CALENDAR_FORMAT
    })];
    if (current > value) value = current;
    if (index === MAX_DAYS) break;
  }
  return value;
};
exports.calcMinStay = calcMinStay;
//# sourceMappingURL=calcMinStay.js.map