"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 {
    details = [],
    occupation = []
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  const detailsByRoom = (0, _getDetailsByRoom.getDetailsByRoom)(details).filter(function () {
    let {
      id
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return occupation.some(function () {
      let {
        id: roomId
      } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      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 {
            id
          } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
          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