"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SCRIPTS = void 0;
var _helpers = require("./helpers");
var _Core = require("../../Core.constants");
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
const SCRIPTS = exports.SCRIPTS = {
  [_Core.PERFORMANCE.AFFILIRED]: {
    components: ['booking'],
    init: () => ({
      src: 'https://scripts.affilired.com/v2/tracking.php'
    }),
    once: true
  },
  [_Core.PERFORMANCE.ANALYTICS]: {
    init: function () {
      let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        idAnalytics = _ref.idAnalytics,
        index = _ref.index,
        gtgEnabled = _ref.gtgEnabled;
      return {
        src: gtgEnabled ? (0, _helpers.gtgSrc)('ga4', index) : "https://www.googletagmanager.com/gtag/js?id=".concat(idAnalytics),
        onLoad: () => {
          window.dataLayer = window.dataLayer || [];
          window.gtag = function () {
            window.dataLayer.push(arguments);
          };
          window.gtag('js', new Date());
          window.gtag('config', idAnalytics, {
            linker: {
              accept_incoming: true
            }
          });
        }
      };
    }
  },
  [_Core.PERFORMANCE.BING]: {
    init: _ref2 => {
      let idBing = _ref2.idBing;
      return {
        src: '//bat.bing.com/bat.js',
        onLoad: () => {
          const uetq = "uetq_".concat(idBing);
          // eslint-disable-next-line no-undef
          window[uetq] = new UET({
            ti: idBing,
            q: window[uetq] || []
          });
          window[uetq].push('consent', 'update', {
            ad_storage: 'granted'
          });
          window[uetq].push('pageLoad');
        }
      };
    }
  },
  [_Core.PERFORMANCE.COMPARE]: {
    components: ['rates', 'checkout', 'booking'],
    init: () => ({
      src: 'https://static.hotelmonitor.info/CmprmInit-min.js',
      onLoad: () => {
        document.addEventListener('CmprmInitLoaded', window.CmprmInit.InitMirai, false);
      }
    }),
    once: true
  },
  [_Core.PERFORMANCE.GOOGLE_ADS]: {
    init: function () {
      let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        cookiePrefix = _ref3.cookiePrefix,
        idAdwords = _ref3.idAdwords,
        index = _ref3.index,
        gtgEnabled = _ref3.gtgEnabled,
        _ref3$loadedComponent = _ref3.loadedComponents,
        loadedComponents = _ref3$loadedComponent === void 0 ? [] : _ref3$loadedComponent;
      return {
        src: gtgEnabled ? (0, _helpers.gtgSrc)('ads', index) : "https://www.googletagmanager.com/gtag/js?id=AW-".concat(idAdwords),
        onLoad: () => {
          window.dataLayer = window.dataLayer || [];
          window.gtag = function () {
            window.dataLayer.push(arguments);
          };
          window.gtag('config', "AW-".concat(idAdwords), {
            conversion_cookie_prefix: cookiePrefix,
            allow_enhanced_conversions: loadedComponents.includes('booking')
          });
        }
      };
    }
  },
  [_Core.PERFORMANCE.GTM]: {
    init: function () {
      let _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        id = _ref4.idGTM,
        index = _ref4.index,
        gtgEnabled = _ref4.gtgEnabled;
      return {
        src: gtgEnabled ? (0, _helpers.gtgSrc)('gtm', index) : "https://www.googletagmanager.com/gtm.js?id=".concat(id),
        onLoad: () => {
          window.dataLayer = window.dataLayer || [];
          (0, _helpers.dataLayerPush)({
            event: 'gtm.js',
            'gtm.start': new Date().getTime()
          });
        }
      };
    }
  },
  [_Core.PERFORMANCE.FACEBOOK]: {
    components: ['rates', 'checkout', 'booking']
  },
  [_Core.PERFORMANCE.MIRAI]: {
    init: function () {
      let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        _ref5$hotel = _ref5.hotel,
        _ref5$hotel2 = _ref5$hotel === void 0 ? {} : _ref5$hotel,
        id = _ref5$hotel2.id,
        instanceId = _ref5.instanceId,
        loadedComponents = _ref5.loadedComponents,
        _ref5$place = _ref5.place,
        _ref5$place2 = _ref5$place === void 0 ? {} : _ref5$place,
        _ref5$place2$id = _ref5$place2.id,
        _ref5$place2$id2 = _ref5$place2$id === void 0 ? [] : _ref5$place2$id,
        _ref5$place2$id3 = _slicedToArray(_ref5$place2$id2, 1),
        hotelId = _ref5$place2$id3[0],
        isHotel = _ref5$place2.isHotel;
      return {
        src: "https://metas.mirai.com/connectivity/gtag/b2c?hotelId=".concat(isHotel && hotelId && !loadedComponents.includes('finder') ? hotelId : id || instanceId)
      };
    },
    once: true
  },
  [_Core.PERFORMANCE.THE_HOTEL_NETWORK]: {
    init: _ref6 => {
      let _ref6$id = _ref6.id,
        id = _ref6$id === void 0 ? '7' : _ref6$id;
      return {
        src: "https://www.thehotelsnetwork.com/js/hotel_price_widget.js?partnership_id=".concat(id)
      };
    }
  }
};
//# sourceMappingURL=PerformanceManager.scripts.js.map