"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPerformance = void 0;
var _helpers = require("../components/helpers");
var _Core = require("../Core.constants");
const _excluded = ["trackingChain", "trackingHotels"];
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); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
const MONALISA_ID = '100379008';
const DEFAULT_PERFORMANCE = [{
  type: 1,
  instances: [{
    idAnalytics: 'G-EW4M987YRE',
    propertyId: '337963856',
    serviceAccount: 'ANALYTICS11',
    id: 42011
  }]
}, {
  type: 2,
  instances: [{
    idAdwords: '604678444',
    conversionLabel: 'S0SLCLqv8toBEKzSqqAC',
    cookiePrefix: 'MIRAI',
    id: 55146
  }]
}, {
  type: 3,
  instances: [{
    idGTM: 'GTM-M3CPG48',
    id: 55265
  }, {
    idGTM: 'GTM-PZG8RRXL',
    id: 55266
  }, {
    idGTM: 'GTM-M3CPG48',
    id: 55267
  }, {
    idGTM: 'GTM-T667BFLL',
    id: 55268
  }]
}, {
  type: 4,
  instances: [{
    id: 47811
  }]
}, {
  type: 5,
  instances: [{
    pixelId: '999999999',
    testEventCode: 'TEST9826',
    id: 55182
  }]
}, {
  type: 6,
  instances: [{
    id: 55179
  }]
}, {
  type: 7,
  instances: [{
    idAffilired: '999999',
    id: 55178
  }]
}, {
  type: 8,
  instances: [{
    idBing: '5979008',
    id: 55180
  }]
}, {
  type: 9,
  instances: [{
    id: 42010
  }]
}];
const getPerformance = function () {
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    {
      tracking: {
        trackingChain,
        trackingHotels
      } = {}
    } = _ref,
    others = _objectWithoutProperties(_ref.tracking, _excluded);
  let hotelId = arguments.length > 1 ? arguments[1] : undefined;
  if (!_helpers.IS_JEST && process.env.NODE_ENV !== 'production' && hotelId !== MONALISA_ID) return DEFAULT_PERFORMANCE;
  if (process.env.NODE_ENV === 'production' && hotelId === MONALISA_ID) return [];

  // ! -- TODO: use of tracking should be a temporary approach ---------------------------------------------------------
  let tracking = others;
  if (trackingChain && trackingHotels) {
    tracking = _objectSpread({}, trackingChain);
    const hotelTracking = hotelId && trackingHotels.find(function () {
      let {
        idTokenProvider: id
      } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return id === parseInt(hotelId);
    });
    hotelTracking && Object.keys(tracking).forEach(key => {
      tracking[key] = [...tracking[key], ...hotelTracking[key]];
    });
  }

  // ! -- TODO: Choose which one will load gtag
  return Object.keys(tracking).length > 0 ? Object.keys(tracking).filter(key => !!_Core.TRACKING[key] && tracking[key].length > 0).map(key => ({
    type: _Core.TRACKING[key],
    instances: tracking[key].map(_ref2 => {
      let {
        configuration = {},
        id: idTracking
      } = _ref2;
      return _objectSpread(_objectSpread({}, configuration !== null ? configuration : {}), {}, {
        idTracking
      });
    })
  })) : undefined;
};
exports.getPerformance = getPerformance;
//# sourceMappingURL=getPerformance.js.map