"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.calcMinStay = void 0;
var _locale = require("@mirai/locale");
var _helpers = require("../../../helpers");
var _RatesExplorer = require("../RatesExplorer.constants");
const calcMinStay = (from, highlights, minNightsWithDeals, rangeMinDays) => {
  let value;
  if (from && minNightsWithDeals) {
    const dateFrom = (0, _locale.parseDate)((0, _locale.dateFormat)(from, {
      format: _helpers.CALENDAR_FORMAT
    }));
    const nextDealIndex = highlights.findIndex(date => (0, _locale.dateDiff)(dateFrom, (0, _locale.parseDate)(date)).days >= 0);
    const dateTo = (0, _locale.parseDate)(highlights[nextDealIndex + minNightsWithDeals - 1]);
    value = dateTo >= dateFrom ? (0, _locale.dateDiff)(dateFrom, dateTo).days + 1 : _RatesExplorer.INVALID_MIN_RANGE_DEALS;
  }
  return value || rangeMinDays;
};
exports.calcMinStay = calcMinStay;
//# sourceMappingURL=calcMinStay.js.map