/**
 * Fontobserver module
 */

var FontObserverHandler = (function () {

	function init(){

		// If the class `fonts-loaded` is already set, we're good
		if(document.documentElement.className.indexOf('fonts-loaded') > -1 ) {
			return;
		}

		// Define the fonts and font variants to observed
		var fontObservers = [];
		var fontFamilies = {
			'Fira Sans': [
				{
					weight: 400,
				},
				{
					weight: 400,
					style: 'italic'
				},
				{
					weight: 700
				},
			],
			// 'Another Font': [
			// 	{
			// 		weight: 400,
			// 		font-variant: small-caps;
			// 	},
			// 	{
			// 		weight: 600
			// 	},
			// ],
		};

		// Init the observer on the defined font settings
		Object.keys(fontFamilies).forEach(function(family) {
			fontObservers.push(fontFamilies[family].map(function(config) {
				return new FontFaceObserver(family, config).load();
			}));
		});

		// Set the `fonts-loaded` class and avoid re-downloading the web fonts
		// over and over again (and do not run the fontobserver script when the
		// font is already available from cache) by setting a cookie
		Promise
			.all(fontObservers)
			.then(function() {
				// document.documentElement.classList.add('fonts-loaded');
				document.documentElement.className += ' fonts-loaded';
				enhance.cookie('fonts_loaded', 'true', 7);
				// cookie.set('fonts_loaded', 'true', 7);
			}, function() {
				console.info('Web fonts could not be loaded in time. Falling back to system fonts.');
			});

	}

	/**
	 * Return public methods
	 */
	return {
		init: init
	};
})();

/**
 * Fontobserver module
 *
 * More info: https://www.bramstein.com/writing/web-font-loading-patterns.html
 */

var FontObserverHandler = (function () {

	function init(){

		// If the class `fonts-loaded` is already set, we're good
		if(document.documentElement.className.indexOf('fonts-loaded') > -1 ) {
		// if (document.documentElement.classList.contains('fonts-loaded')) {
			return;
		}

		// Define the fonts and font variants to observed
		var firasans_book = new FontFaceObserver('FiraSans Book', {
			weight: 400
		});
		var firasans_bold = new FontFaceObserver('FiraSans Bold', {
			weight: 700
		});

		// Loading groups of fonts with a timeout
		Promise.all([
			firasans_book.load(),
			firasans_bold.load()
		]).then(function () {
			document.documentElement.className += ' fonts-loaded';
			// document.documentElement.classList.add('fonts-loaded');
			enhance.cookie('fonts_loaded', 'true', 7);
			// console.log('Kawak fonts have loaded.');
		}).catch(function () {
			// document.documentElement.classList.add('fonts-failed');
			console.info('Web fonts could not be loaded in time. Falling back to system fonts.');
		});

		// // Timer helper function
		// function timer(time) {
		// 	return new Promise(function (resolve, reject) {
		// 		setTimeout(reject, time);
		// 	});
		// }

		// // Loading groups of fonts with a timeout
		// Promise.race([
		// 	timer(3000),
		// 	kawak_light.load(),
		// 	kawak_regular.load()
		// ]).then(function () {
		// 	document.documentElement.className += ' fonts-loaded';
		// 	// document.documentElement.classList.add('fonts-loaded');
		// 	enhance.cookie('fonts_loaded', 'true', 7);
		// 	// console.info('Kawak fonts have loaded.');
		// }).catch(function () {
		// 	// document.documentElement.classList.add('fonts-failed');
		// 	console.info('Kawak fonts loading has timed out (> 3 sec.). Falling back to system fonts.');
		// });

		// // Prioritised loading
		// kawak_light.load().then(function () {
		// 	document.documentElement.className += ' kawak-light-loaded';
		// 	console.info('Kawak Light font has loaded.');

		// 	kawak_regular.load().then(function () {
		// 		document.documentElement.className += ' kawak-regular-loaded';
		// 		document.documentElement.className += ' fonts-loaded';
		// 		console.info('Kawak Regular font has loaded.');
		// 	});
		// });

	}

	/**
	 * Return public methods
	 */
	return {
		init: init
	};
})();

Update FontFaceObserver code.