/**
	This service worker is separate from the DOM and is here to catch messages to the app when ot is closed, or running in the background.
**/
const fcmVersion = '7.17.0'; //7.16.1 == 7.17.0
importScripts("https://www.gstatic.com/firebasejs/"+fcmVersion+"/firebase-app.js");
//importScripts("https://www.gstatic.com/firebasejs/"+fcmVersion+"/firebase-analytics.js");
importScripts("https://www.gstatic.com/firebasejs/"+fcmVersion+"/firebase-messaging.js");

var firebaseConfig = 
{
	apiKey:				"AIzaSyBe9PDJ2CIHnjAn5hY-4SYCS4pmA3enZb0",
	authDomain: 		"champ-web-app.firebaseapp.com",
	databaseURL:		"https://champ-web-app.firebaseio.com",
	projectId:			"champ-web-app",
	storageBucket:		"champ-web-app.appspot.com",
	messagingSenderId:	"462083300714",
	appId:				"1:462083300714:web:c04e7b778aa760cfd11913",
	measurementId:		"G-H23C13MVP1"
};

var window = self.window;
firebase.initializeApp(firebaseConfig);
//firebase.analytics();

const messaging = firebase.messaging();
// [END get_messaging_object]
// [START set_public_vapid_key]
// Add the public key generated from the console here.
messaging.usePublicVapidKey('BBRqZmtVUlwC8RBxKpqHwnmBc82q6Xt3rlETq1kNblNk1kBjxxmWrwXCDxzb8lixieZqe74nI2BrmXaEP-OCyRk');

messaging.setBackgroundMessageHandler
(
	function(payload) 
	{
		var opts = 
		{
			body: payload.data.body, 
			icon: 'https://champ.jona.co.za/media/images/manifest_logo.png',
			badge: 'https://champ.jona.co.za/media/images/notification_badge.png', 
			vibrate:[100,50,100], 
			silent:false,
			data: {url:payload.data.click_action},	
			actions: [{action: "open_url", title: "Open Now"}]									
		};
		return self.registration.showNotification(payload.data.title, opts);
	}
);