"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getOccupationTotals = void 0;
var _constants = require("./constants");
const CHILD = _constants.OCCUPATION_TYPE.CHILD;
const getOccupationTotals = function () {
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    _ref$infantAge = _ref.infantAge,
    infantAge = _ref$infantAge === void 0 ? 0 : _ref$infantAge,
    _ref$occupation = _ref.occupation,
    occupation = _ref$occupation === void 0 ? [] : _ref$occupation;
  const occupationItems = occupation.flat().filter(function () {
    let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      type = _ref2.type;
    return type === CHILD;
  }).reduce(function () {
    let totalAges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    let _ref3 = arguments.length > 1 ? arguments[1] : undefined,
      _ref3$ages = _ref3.ages,
      ages = _ref3$ages === void 0 ? [] : _ref3$ages;
    return [...totalAges, ...ages];
  }, []);
  return {
    adults: occupation.flat().reduce(function (total) {
      let _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        amount = _ref4.amount,
        type = _ref4.type;
      return total + (type !== CHILD ? amount : 0);
    }, 0),
    babies: occupationItems.filter(age => age < infantAge).length,
    children: occupationItems.filter(age => age >= infantAge).length
  };
};
exports.getOccupationTotals = getOccupationTotals;
//# sourceMappingURL=getOccupationTotals.js.map