"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getConsentMode = void 0;
const getConsentMode = function () {
  let readGoogleData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  let granted;
  const consentManagement = (window.dataLayer || []).filter(item => item[0] === 'consent' && item[1] === 'update').map(item => item[2]).pop() || {};
  if (Object.values(consentManagement).length) {
    granted = Object.values(consentManagement).filter(value => value === 'granted').length >= 1;
  }
  if (readGoogleData && !granted) {
    const _ref = window.google_tag_data || {},
      _ref$ics = _ref.ics,
      _ref$ics2 = _ref$ics === void 0 ? {} : _ref$ics,
      _ref$ics2$entries = _ref$ics2.entries,
      _ref$ics2$entries2 = _ref$ics2$entries === void 0 ? {} : _ref$ics2$entries,
      _ref$ics2$entries2$ad = _ref$ics2$entries2.ad_personalization,
      ad_personalization = _ref$ics2$entries2$ad === void 0 ? {} : _ref$ics2$entries2$ad,
      _ref$ics2$entries2$ad2 = _ref$ics2$entries2.ad_storage,
      ad_storage = _ref$ics2$entries2$ad2 === void 0 ? {} : _ref$ics2$entries2$ad2,
      _ref$ics2$entries2$ad3 = _ref$ics2$entries2.ad_user_data,
      ad_user_data = _ref$ics2$entries2$ad3 === void 0 ? {} : _ref$ics2$entries2$ad3,
      _ref$ics2$entries2$an = _ref$ics2$entries2.analytics_storage,
      analytics_storage = _ref$ics2$entries2$an === void 0 ? {} : _ref$ics2$entries2$an;
    const hasValue = function () {
      let obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return obj.default !== undefined;
    };
    if (hasValue(ad_personalization) || hasValue(ad_storage) || hasValue(ad_user_data) || hasValue(analytics_storage)) {
      granted = Object.values({
        ad_personalization,
        ad_storage,
        ad_user_data,
        analytics_storage
      }).filter(function () {
        let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
        return value.update !== undefined ? value.update : value.default;
      }).length >= 1;
    }
  }
  return granted;
};
exports.getConsentMode = getConsentMode;
//# sourceMappingURL=getConsentMode.js.map