export function getCookie(name) {
	var v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')
	return v ? v[2] : null
}

export function setCookie(name, value, days) {
	var d = new Date()
	d.setTime(d.getTime() + 24 * 60 * 60 * 1000 * days)
	document.cookie = name + '=' + value + ';path=/;expires=' + d.toGMTString()
}

export function deleteCookie(name) {
	setCookie(name, '', -1)
}

$(function() {
	var $cookieBar = $('.js-cookie-bar')

	$cookieBar.addClass('is-loaded')

	if (getCookie('use-cookies')) {
		$cookieBar.addClass('is-closed')
	}

	$('.js-accept-cookie').on('click', function() {
		setCookie('use-cookies', true, 365)
		$cookieBar.addClass('is-closed')
	})
})
