"use strict";

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