"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.select = void 0;
var _filterItem2 = require("./filterItem");
const _excluded = ["amenities", "availability", "bedTypes", "size"];
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
const select = function () {
  let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
    _ref$amenities = _ref.amenities,
    filterAmenities = _ref$amenities === void 0 ? [] : _ref$amenities,
    bedType = _ref.bedType,
    board = _ref.board,
    freeCancellation = _ref.freeCancellation,
    _ref$priceRange = _ref.priceRange,
    priceRange = _ref$priceRange === void 0 ? {} : _ref$priceRange,
    _ref$sizeRange = _ref.sizeRange,
    sizeRange = _ref$sizeRange === void 0 ? {} : _ref$sizeRange;
  let _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
    _ref2$priceFactor = _ref2.priceFactor,
    priceFactor = _ref2$priceFactor === void 0 ? 1 : _ref2$priceFactor;
  return items.filter(function () {
    let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      _ref3$amenities = _ref3.amenities,
      amenities = _ref3$amenities === void 0 ? [] : _ref3$amenities,
      _ref3$availability = _ref3.availability,
      availability = _ref3$availability === void 0 ? 0 : _ref3$availability,
      _ref3$bedTypes = _ref3.bedTypes,
      bedTypes = _ref3$bedTypes === void 0 ? [] : _ref3$bedTypes,
      _ref3$size = _ref3.size,
      rawSize = _ref3$size === void 0 ? '' : _ref3$size,
      item = _objectWithoutProperties(_ref3, _excluded);
    const hasAmenities = filterAmenities.length === 0 || filterAmenities.every(item => amenities.map(_ref4 => {
      let id = _ref4.id;
      return id;
    }).includes(item));
    const hasBedTypes = !bedType || bedTypes.includes(bedType);
    let hasSize = true;
    let _rawSize$split = rawSize.split(' '),
      _rawSize$split2 = _slicedToArray(_rawSize$split, 1),
      size = _rawSize$split2[0];
    if (size) {
      const maxSize = sizeRange.max,
        minSize = sizeRange.min;
      size = parseInt(size);
      hasSize = (!minSize || size >= minSize) && (!maxSize || size <= maxSize);
    }
    const _filterItem = (0, _filterItem2.filterItem)(item, {
        board,
        freeCancellation,
        priceRange: {
          max: priceRange.max,
          min: priceRange.min
        }
      }, priceFactor),
      _filterItem$boards = _filterItem.boards,
      boards = _filterItem$boards === void 0 ? [] : _filterItem$boards,
      _filterItem$cancellat = _filterItem.cancellations,
      cancellations = _filterItem$cancellat === void 0 ? [] : _filterItem$cancellat,
      _filterItem$rates = _filterItem.rates,
      rates = _filterItem$rates === void 0 ? [] : _filterItem$rates;
    const hasOptions = availability === 0 || boards.length > 0 && (cancellations.length > 0 || rates.length > 0);
    return hasAmenities && hasBedTypes && hasSize && hasOptions;
  });
};
exports.select = select;
//# sourceMappingURL=select.js.map