"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getDiscount = void 0;
var _Rates = require("../../../Rates.constants");
const getDiscount = function () {
  let {
    cart = [],
    items = []
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return cart.reduce(function (total) {
    var _items$find, _items$find$rates, _breakdown$find;
    let {
      discount: {
        breakdown = []
      } = {},
      rateId,
      roomId
    } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    const {
      isClub
    } = ((_items$find = items.find(_ref => {
      let {
        id
      } = _ref;
      return id === roomId;
    })) === null || _items$find === void 0 ? void 0 : (_items$find$rates = _items$find.rates) === null || _items$find$rates === void 0 ? void 0 : _items$find$rates.find(_ref2 => {
      let {
        id
      } = _ref2;
      return id === rateId;
    })) || {};
    const current = ((_breakdown$find = breakdown.find(_ref3 => {
      let {
        type
      } = _ref3;
      return type === _Rates.DISCOUNT_TYPE.CLUB || type === _Rates.DISCOUNT_TYPE.DEAL && isClub;
    })) === null || _breakdown$find === void 0 ? void 0 : _breakdown$find.value) || 0;
    return total + current;
  }, 0);
};
exports.getDiscount = getDiscount;
//# sourceMappingURL=getDiscount.js.map