"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getOccupationSummary = void 0;
var _locale = require("@mirai/locale");
var _constants = require("./constants");
var _getAccommodationLabel = require("./getAccommodationLabel");
var _getOccupationLabel = require("./getOccupationLabel");
const {
  ADULT,
  CHILD,
  GUEST
} = _constants.OCCUPATION_TYPE;
const getOccupationSummary = function () {
  let rooms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  let translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _locale.translate;
  let typeAccommodation = arguments.length > 2 ? arguments[2] : undefined;
  const getCount = (room, filterType) => room.filter(function () {
    let {
      type
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return type === filterType;
  }).reduce(function (previous) {
    let {
      amount = 0
    } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    return previous + amount;
  }, 0);
  let adults = 0;
  let children = 0;
  let guests = 0;
  rooms.forEach(room => {
    adults += getCount(room, ADULT);
    children += getCount(room, CHILD);
    guests += getCount(room, GUEST);
  });
  const amount = adults || guests;
  const captionAdults = amount > 0 ? typeAccommodation ? (0, _getOccupationLabel.getOccupationLabel)({
    amount,
    type: adults > 0 ? ADULT : GUEST
  }, translate) : amount : '';
  const captionChildren = children > 0 ? typeAccommodation ? ", ".concat((0, _getOccupationLabel.getOccupationLabel)({
    amount: children,
    type: CHILD
  }, translate)) : " + ".concat(children) : '';
  const captionAccommodation = typeAccommodation ? " \xB7 ".concat(rooms.length > 0 ? "".concat(rooms.length, " ") : '').concat((0, _getAccommodationLabel.getAccommodationLabel)({
    plural: rooms.length > 1,
    type: typeAccommodation
  }, translate)) : '';
  return "".concat(captionAdults).concat(captionChildren).concat(captionAccommodation);
};
exports.getOccupationSummary = getOccupationSummary;
//# sourceMappingURL=getOccupationSummary.js.map