"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getDataSource = void 0;
var _getPlacesOptions = require("./getPlacesOptions");
var _Finder = require("../Finder.constants");
const getDataSource = function () {
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    _ref$config = _ref.config,
    _ref$config2 = _ref$config === void 0 ? {} : _ref$config,
    _ref$config2$accomoda = _ref$config2.accomodation,
    _ref$config2$accomoda2 = _ref$config2$accomoda === void 0 ? {} : _ref$config2$accomoda,
    _ref$config2$accomoda3 = _ref$config2$accomoda2.calendar,
    calendar = _ref$config2$accomoda3 === void 0 ? {} : _ref$config2$accomoda3,
    occupation = _ref$config2$accomoda2.occupation,
    _ref$config2$accomoda4 = _ref$config2$accomoda2.rooms,
    _ref$config2$accomoda5 = _ref$config2$accomoda4 === void 0 ? {} : _ref$config2$accomoda4,
    maxRooms = _ref$config2$accomoda5.maxOccupation,
    _ref$config2$accomoda6 = _ref$config2$accomoda2.variants,
    variants = _ref$config2$accomoda6 === void 0 ? [] : _ref$config2$accomoda6,
    chainSelector = _ref$config2.chainSelector,
    language = _ref.language,
    promo = _ref.promo,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? _Finder.TYPE.HOTEL : _ref$type;
  let places;
  let placesSource;
  if (type === _Finder.TYPE.CHAIN && chainSelector) {
    const _chainSelector$placeH = chainSelector.placeHolder,
      placeHolder = _chainSelector$placeH === void 0 ? {} : _chainSelector$placeH,
      _chainSelector$trees = chainSelector.trees,
      trees = _chainSelector$trees === void 0 ? [] : _chainSelector$trees;
    places = {
      options: (0, _getPlacesOptions.getPlacesOptions)(trees, language),
      placeholder: placeHolder[language]
    };
    placesSource = trees;
  }
  return {
    calendar,
    occupation,
    places,
    placesSource,
    promo: promo ? {
      code: promo.code
    } : undefined,
    maxRooms,
    variants
  };
};
exports.getDataSource = getDataSource;
//# sourceMappingURL=getDataSource.js.map