(window.adsbygoogle = window.adsbygoogle || []).pauseAdRequests = 1;'use strict';

(function () {
	var makeStub = function makeStub() {
		var TCFAPI_LOCATOR_NAME = '__tcfapiLocator';
		var queue = [],
			legacyQueue = [];
		var win = window;
		var cmpFrame = undefined;

		function addLocatorFrame() {
			var document = win.document;
			var otherCMP = !!win.frames[TCFAPI_LOCATOR_NAME];

			if (!otherCMP) {
				if (document.body) {
					var iframe = document.createElement('iframe');
					iframe.style.cssText = 'display:none';
					iframe.name = TCFAPI_LOCATOR_NAME;
					document.body.appendChild(iframe);
				} else {
					setTimeout(addLocatorFrame, 5);
				}
			}
			return !otherCMP;
		}

		function tcfApiHandler() {
			var gdprApplies = win.gdprApplies;

			for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
				args[_key] = arguments[_key];
			}

			if (!args.length) {
				// returns the queue when the full CMP implementation loads
				return queue;
			} else if (args[0] === 'setGdprApplies') {
				// allows publisher to indicate that they apply GDPR rules to all traffic
				if (args.length > 3 && parseInt(args[1], 10) === 2 && typeof args[3] === 'boolean') {
					gdprApplies = args[3];
					win.gdprApplies = gdprApplies;
					if (typeof args[2] === 'function') {
						args[2]({ gdprApplies: gdprApplies }, true);
					}
				}
			} else if (args[0] === 'ping') {
				if (typeof args[2] === 'function') {
					args[2]({
						gdprApplies: gdprApplies,
						cmpLoaded: false,
						cmpStatus: 'stub',
						apiVersion: '2.0'
					}, true);
				}
			} else {
				queue.push(args);
			}
		}

		function messageHandler(event) {
			var data = event && event.data;
			var msgIsString = typeof data === 'string';

			var json = {};
			try {
				if (msgIsString) {
					json = JSON.parse(event.data);
				} else if (typeof data === 'object' && data.constructor === Object) {
					json = data;
				}
			} catch (ignored) {}

			var tcfApiCall = json && json.__tcfapiCall;
			if (tcfApiCall) {
				window.__tcfapi(tcfApiCall.command, tcfApiCall.version, function (returnValue, success) {
					var returnMsg = {
						__tcfapiReturn: {
							returnValue: returnValue,
							success: success,
							callId: tcfApiCall.callId
						}
					};
					if (msgIsString) {
						returnMsg = JSON.stringify(returnMsg);
					}
					event.source.postMessage(returnMsg, '*');
				}, tcfApiCall.parameter);
			}
		}

		// Iterate up to the top window checking for an already-created "__tcfapilLocator" frame on every level
		// If one exists already then we are not the master CMP and will not queue commands.
		while (win) {
			try {
				if (win.frames[TCFAPI_LOCATOR_NAME]) {
					cmpFrame = win;
					break;
				}
			} catch (ignore) {}
			if (win === window.top) {
				break;
			}
			win = win.parent;
		}

		if (!cmpFrame) {
			addLocatorFrame();
			win.__tcfapi = tcfApiHandler;
			win.addEventListener('message', messageHandler, false);
		}
	};

	if (typeof module !== 'undefined') {
		module.exports = makeStub;
	} else {
		makeStub();
	}
})();
