$(function () {
	function newNotif(info){
		var content = ''
		if (info.type == "image"){
			content = `<div class="img_notif" style="background-image:url('`+info.content+`')"></div>`
		} else if(info.type == "icone"){
			content = `<i class="`+info.content+` icone_notif"></i>`
		} else if(info.type == "error"){
			content = `<i class="fa-solid fa-circle-xmark icone_notif"></i>`
		} else {
			content = `<i class="fa-solid fa-circle-info icone_notif"></i>`
		}
		var uniqueId = Math.floor(Math.random() * 99999);
		$("#containerNotif").append(`
			<div id="`+uniqueId+`" class="notif animate__animated animate__slideInLeft animate_duree">
				<div class="content_notif">
					`+content+`
				</div>
				<div class="content_message">
					<div class="message_notif">
						`+info.notif+`
					</div>
				</div>
			</div>
		`)
		setTimeout(function(){
			$("#"+uniqueId).addClass('animate__animated animate__slideOutLeft animate_duree');
			setTimeout(function(){
				$("#"+uniqueId).remove()
				$.post("http://spyoo_notif/removeQueue", JSON.stringify({}))
			}, 500)
		}, info.time);
	}
	window.addEventListener("message", function(event){
		var item = event.data;
		if (item.type === "notif"){
			newNotif(item.info)
		}
	})
})
