"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getAccommodationType = void 0;
var _constants = require("./constants");
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; }
const APARTMENT = _constants.ACCOMMODATION_TYPE.APARTMENT,
  ACCOMMODATION = _constants.ACCOMMODATION_TYPE.ACCOMMODATION,
  PITCH = _constants.ACCOMMODATION_TYPE.PITCH,
  ROOM = _constants.ACCOMMODATION_TYPE.ROOM,
  VILLA = _constants.ACCOMMODATION_TYPE.VILLA;
const DEFAULT_PLACE = 'ROOMS';
const PLACE_INDIVIDUAL = {
  APARTMENTS: APARTMENT,
  LODGINGS: ACCOMMODATION,
  PLOTS: PITCH,
  ROOMS: ROOM,
  VILLA: VILLA
};
const getAccommodationType = function () {
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    dataSource = _ref.dataSource,
    _ref$hotels = _ref.hotels,
    hotels = _ref$hotels === void 0 ? [] : _ref$hotels,
    _ref$individual = _ref.individual,
    individual = _ref$individual === void 0 ? DEFAULT_PLACE : _ref$individual;
  let result;
  if (dataSource) {
    const types = Object.entries(dataSource).filter(_ref2 => {
      let _ref3 = _slicedToArray(_ref2, 1),
        id = _ref3[0];
      return hotels.length === 0 || hotels.includes(id);
    }).map(_ref4 => {
      let _ref5 = _slicedToArray(_ref4, 2),
        type = _ref5[1].lodgingDenomination;
      return type;
    }) || [];
    if (types.includes(ROOM)) result = ROOM;else if (types.includes(ACCOMMODATION)) result = ACCOMMODATION;else if (types.includes(APARTMENT)) result = APARTMENT;else if (types.includes(PITCH)) result = PITCH;else if (types.includes(VILLA)) result = VILLA;
  }
  return result || PLACE_INDIVIDUAL[individual];
};
exports.getAccommodationType = getAccommodationType;
//# sourceMappingURL=getAccommodationType.js.map