"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 _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    _ref$device = _ref.device,
    _ref$device2 = _ref$device === void 0 ? {} : _ref$device,
    mobile = _ref$device2.mobile,
    _ref$response = _ref.response,
    _ref$response2 = _ref$response === void 0 ? {} : _ref$response,
    _ref$response2$tracki = _ref$response2.tracking,
    tracking = _ref$response2$tracki === void 0 ? {} : _ref$response2$tracki,
    _ref$store = _ref.store,
    _ref$store2 = _ref$store === void 0 ? {} : _ref$store,
    _ref$store2$finder = _ref$store2.finder,
    _ref$store2$finder2 = _ref$store2$finder === void 0 ? {} : _ref$store2$finder,
    _ref$store2$finder2$c = _ref$store2$finder2.calendar,
    calendar = _ref$store2$finder2$c === void 0 ? [] : _ref$store2$finder2$c,
    _ref$store2$hotel = _ref$store2.hotel,
    _ref$store2$hotel2 = _ref$store2$hotel === void 0 ? {} : _ref$store2$hotel,
    accommodationType = _ref$store2$hotel2.accommodationType,
    _ref$store2$hotel2$va = _ref$store2$hotel2.variants,
    variants = _ref$store2$hotel2$va === void 0 ? {} : _ref$store2$hotel2$va,
    language = _ref$store2.language;
  // ! -- TODO: Try to get all data from store -------------------------------------------------------------------------
  const _fetchUrlParams = (0, _helpers.fetchUrlParams)(location.search),
    idchain = _fetchUrlParams.idchain,
    hotelId = _fetchUrlParams.idtokenprovider;

  // ! -- TODO: use of tracking should be a temporary approach ---------------------------------------------------------
  const cancelComment = tracking.cancelComment,
    cancellationDate = tracking.cancellationDate,
    cancelReason = tracking.cancelReason,
    _tracking$hotelInfo = tracking.hotelInfo,
    _tracking$hotelInfo2 = _tracking$hotelInfo === void 0 ? {} : _tracking$hotelInfo,
    _tracking$hotelInfo2$ = _tracking$hotelInfo2.currency,
    hotelCurrency = _tracking$hotelInfo2$ === void 0 ? {} : _tracking$hotelInfo2$,
    propertyName = _tracking$hotelInfo2.propertyName,
    propertyType = _tracking$hotelInfo2.propertyType,
    idReservation = tracking.idReservation,
    reservationDate = tracking.reservationDate,
    totalPriceWithTaxes = tracking.totalPriceWithTaxes;
  const _dateDiff = (0, _locale.dateDiff)(...calendar),
    days = _dateDiff.days;
  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