const snippetsContainer = document.getElementById('snippets-container')

let pathname = window.location.pathname.replace('/soupboat/si16-app/','')
let page = pathname.substring(0, pathname.length - 1);
let endpoint = `https://hub.xpub.nl/soupboat/si16-app/api/is-event-mode/?page=${page}`;

fetch(endpoint)
	.then((response) => response.json())
	.then((data) => {
		if (data.event && data.snippets) {
			data.snippets.forEach(snippet=>{
            console.log(snippet)
            if(snippet.type == 'text') textSnippet(snippet.content)
            if(snippet.type == 'image') imageSnippet(snippet)
                
            })
		}
	});

function textSnippet(text){
    let snippetBubble = document.createElement('div')
    snippetBubble.classList.add('snippet')
    snippetBubble.innerHTML = text
    snippetsContainer.appendChild(snippetBubble)
}

function imageSnippet(snippet){
    let snippetBubble = document.createElement('img')
    snippetBubble.classList.add('snippet')
    snippetBubble.src = "/soupboat/si16-app" + snippet.content
    snippetsContainer.appendChild(snippetBubble)
}