"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.bookingCancel = void 0;
var _locale = require("@mirai/locale");
var _Core = require("../../../../Core.constants");
var _helpers = require("../../../../helpers");
var _helpers2 = require("../../helpers");
var _legacy = require("../helpers/legacy");
const ACCOMMODATION_TYPE_NAME = Object.keys(_Core.ACCOMMODATION_TYPE);
const bookingCancel = function () {
  var _variants$hotelId;
  let {
    device: {
      mobile
    } = {},
    response: {
      tracking = {}
    } = {},
    store: {
      finder: {
        calendar = []
      } = {},
      hotel: {
        accommodationType,
        variants = {}
      } = {},
      language
    } = {}
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  // ! -- TODO: Try to get all data from store -------------------------------------------------------------------------
  const {
    idchain,
    idtokenprovider: hotelId
  } = (0, _helpers.fetchUrlParams)(location.search);

  // ! -- TODO: use of tracking should be a temporary approach ---------------------------------------------------------
  const {
    cancelComment,
    cancellationDate,
    cancelReason,
    hotelInfo: {
      currency: hotelCurrency = {},
      propertyName,
      propertyType
    } = {},
    idReservation,
    reservationDate,
    totalPriceWithTaxes
  } = tracking;
  const {
    days
  } = (0, _locale.dateDiff)(...calendar);
  const dataLayer = {
    cancelComment,
    cancellationDate,
    cancelReason,
    chainId: idchain,
    checkin: (0, _locale.dateFormat)(calendar[0], {
      format: 'DD/MM/YYYY'
    }),
    checkout: (0, _locale.dateFormat)(calendar[1], {
      format: 'DD/MM/YYYY'
    }),
    currency: hotelCurrency.code,
    device: mobile ? 'MOBILE' : 'DESKTOP_TABLET',
    home: window.location.host,
    idHotel: hotelId,
    language,
    lodgingDenomination: ACCOMMODATION_TYPE_NAME[((_variants$hotelId = variants[hotelId]) === null || _variants$hotelId === void 0 ? void 0 : _variants$hotelId.accommodationType) || accommodationType],
    nights: days,
    propertyName,
    propertyType,
    reservationCode: idReservation,
    reservationDate,
    step: 'CANCELLATION',
    totalPriceWithTaxes: (0, _legacy.formatPrice)(totalPriceWithTaxes, hotelCurrency)
  };
  (0, _helpers2.dataLayerPush)({
    event: 'mirai.cancelled',
    'mirai.data': dataLayer
  });
  return dataLayer;
};
exports.bookingCancel = bookingCancel;
//# sourceMappingURL=bookingCancel.js.map