"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.select = void 0;
var _filterItem = require("./filterItem");
const _excluded = ["amenities", "availability", "bedTypes", "size"];
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 {
    amenities: filterAmenities = [],
    bedType,
    board,
    freeCancellation,
    priceRange = {},
    sizeRange = {}
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  let {
    priceFactor = 1
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  return items.filter(function () {
    let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      {
        amenities = [],
        availability = 0,
        bedTypes = [],
        size: rawSize = ''
      } = _ref,
      item = _objectWithoutProperties(_ref, _excluded);
    const hasAmenities = filterAmenities.length === 0 || filterAmenities.every(item => amenities.map(_ref2 => {
      let {
        id
      } = _ref2;
      return id;
    }).includes(item));
    const hasBedTypes = !bedType || bedTypes.includes(bedType);
    let hasSize = true;
    let [size] = rawSize.split(' ');
    if (size) {
      const {
        max: maxSize,
        min: minSize
      } = sizeRange;
      size = parseInt(size);
      hasSize = (!minSize || size >= minSize) && (!maxSize || size <= maxSize);
    }
    const {
      boards = [],
      cancellations = [],
      rates = []
    } = (0, _filterItem.filterItem)(item, {
      board,
      freeCancellation,
      priceRange: {
        max: priceRange.max,
        min: priceRange.min
      }
    }, priceFactor);
    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