"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getClubRate = void 0;
var _Rates = require("../Rates.constants");
const getClubRate = function () {
  var _items$find, _items$find$rates;
  let {
    board: {
      discount: {
        breakdown = []
      } = {},
      rateId,
      roomId
    } = {},
    dataSource: {
      items = []
    } = {},
    rate: propRate
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  const rate = propRate || ((_items$find = items.find(function () {
    let {
      id
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    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(function () {
    let {
      id
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return id === rateId;
  })) || {};
  const discount = !!breakdown.find(_ref => {
    let {
      type
    } = _ref;
    return type === _Rates.DISCOUNT_TYPE.CLUB;
  });
  if (!discount && !rate.isClub) return;
  return {
    discount,
    rate: rate.isClub
  };
};
exports.getClubRate = getClubRate;
//# sourceMappingURL=getClubRate.js.map