"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getRoomSelectionData = void 0;
var _getDetailsByRoom = require("./getDetailsByRoom");
const isRoomMatch = (left, right) => left === right || String(left) === String(right);
const getRoomSelectionData = function () {
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    _ref$details = _ref.details,
    details = _ref$details === void 0 ? [] : _ref$details,
    _ref$occupation = _ref.occupation,
    occupation = _ref$occupation === void 0 ? [] : _ref$occupation;
  const detailsByRoom = (0, _getDetailsByRoom.getDetailsByRoom)(details).filter(function () {
    let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      id = _ref2.id;
    return occupation.some(function () {
      let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        roomId = _ref3.id;
      return id !== undefined && isRoomMatch(roomId, id);
    });
  });
  if (detailsByRoom.length > 0) {
    return detailsByRoom.map(function () {
      let detail = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return {
        detail,
        room: {
          id: detail.id,
          index: detail.detailIndex
        },
        roomOccupation: occupation.find(function () {
          let _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
            id = _ref4.id;
          return id !== undefined && isRoomMatch(id, detail.id);
        })
      };
    });
  }
  return occupation.map(function () {
    let roomOccupation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    let index = arguments.length > 1 ? arguments[1] : undefined;
    return {
      room: {
        id: roomOccupation.id,
        index
      },
      roomOccupation
    };
  });
};
exports.getRoomSelectionData = getRoomSelectionData;
//# sourceMappingURL=getRoomSelectionData.js.map