"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getOccupationTotals = void 0;
var _constants = require("./constants");
const {
  CHILD
} = _constants.OCCUPATION_TYPE;
const getOccupationTotals = function () {
  let {
    infantAge = 0,
    occupation = []
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  const occupationItems = occupation.flat().filter(function () {
    let {
      type
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return type === CHILD;
  }).reduce(function () {
    let totalAges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    let {
      ages = []
    } = arguments.length > 1 ? arguments[1] : undefined;
    return [...totalAges, ...ages];
  }, []);
  return {
    adults: occupation.flat().reduce(function (total) {
      let {
        amount,
        type
      } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      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