"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.bookingResponse = void 0;
var _synapse = require("./synapse");
var _legacy = require("../helpers/legacy");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const bookingResponse = function () {
  let {
    instances = [],
    response: {
      tracking = {}
    } = {},
    store = {}
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  // ! -- TODO: use of tracking should be a temporary approach ---------------------------------------------------------
  const {
    bookingValues: {
      checkin,
      checkout,
      occupation,
      coupon = '',
      nights
    } = {},
    hotelInfo = {},
    idReservation,
    pendingPayment,
    reservedExtras = {},
    reservedRooms = [],
    totalPriceCommission,
    totalPriceWithoutTaxes,
    totalTaxes
  } = tracking;
  const {
    currency: hotelCurrency = {},
    propertyName,
    propertyType
  } = hotelInfo;
  const {
    urlParams: {
      idHotel
    } = {}
  } = store;
  const commonProps = {
    affiliation: propertyName,
    coupon,
    currency: hotelCurrency.code,
    item_brand: propertyName
  };
  const rooms = reservedRooms.map(_ref => {
    let {
      averagePriceWithoutTaxes,
      defaultBoardDescription,
      numRoomsToReserve,
      rateId,
      rateName,
      roomTypeName
    } = _ref;
    return _objectSpread(_objectSpread({}, commonProps), {}, {
      item_category: 'Habitación',
      item_category2: rateName,
      item_category3: defaultBoardDescription,
      item_category4: propertyType,
      item_category5: idHotel,
      item_name: roomTypeName,
      price: (0, _legacy.formatPrice)(averagePriceWithoutTaxes, hotelCurrency),
      quantity: numRoomsToReserve * nights,
      item_id: "".concat(rateId)
    });
  });
  const extras = Object.keys(reservedExtras).map(key => reservedExtras[key]).map(_ref2 => {
    let {
      id,
      name,
      multiplierPrice,
      priceWithoutTaxes,
      type
    } = _ref2;
    return _objectSpread(_objectSpread({}, commonProps), {}, {
      item_category: 'Extra',
      item_category2: type,
      item_name: name,
      price: (0, _legacy.formatPrice)(priceWithoutTaxes, hotelCurrency),
      quantity: multiplierPrice,
      item_id: "".concat(id)
    });
  });
  const transaction_id = "Reservation code ".concat(idReservation);
  const value = {
    affiliation: propertyName,
    coupon,
    currency: hotelCurrency.code,
    items: [...rooms, ...extras],
    shipping: totalPriceCommission,
    tax: (0, _legacy.formatPrice)(totalTaxes, hotelCurrency),
    transaction_id,
    value: (0, _legacy.formatPrice)(totalPriceWithoutTaxes, hotelCurrency),
    send_to: instances.map(function () {
      let {
        idAnalytics
      } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return idAnalytics;
    })
  };
  window.gtag('event', pendingPayment ? 'BTP' : 'purchase', value);
  window.gtag('event', 'data_search_info', {
    checkin,
    checkout,
    hotelId: idHotel,
    coupon,
    non_interaction: true,
    occupation,
    send_to: instances.map(function () {
      let {
        idAnalytics
      } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return idAnalytics;
    }),
    step: 'CONFIRMATION',
    transaction_id
  });
  (0, _synapse.synapse)(_objectSpread(_objectSpread({
    event: 'chat_booking'
  }, store), {}, {
    instances
  }));
  return value;
};
exports.bookingResponse = bookingResponse;
//# sourceMappingURL=bookingResponse.js.map