function handleReturnData(data) {
    let videos = data.items;

    if (data.prevPageToken) {
        document.getElementById('prevPage').setAttribute("prev", data.prevPageToken);
    }

    if (data.nextPageToken) {
        document.getElementById('nextPage').setAttribute("next", data.nextPageToken);
        document.getElementById('loadMore').setAttribute("continuation", data.nextPageToken);
    }

    // Insert videos
    var vidTemplate  = document.querySelector('#vidTemplate');
    let title        = "";
    let slug         = ""
    let thumbnail    = "";
    videos.forEach(video => {
        title         = video.snippet.title;
        slug          = video.id.videoId;
        thumbnail     = video.snippet.thumbnails.high.url;
        let vidClone  = document.importNode(vidTemplate.content, true);

        createElmBlock(vidClone, title, slug, thumbnail);
    });
}

const createElmBlock = (elm, title, slug, thumbnail) => {
    containerTag       = elm.firstElementChild;
    let inputTag       = elm.querySelector("input");
    containerTag.style = "background-image: url('" + thumbnail + "')";
    inputTag.className = "videoTitle";
    containerTag.title = title;
    inputTag.value     = title;

    containerTag.setAttribute("slug", slug);
    containerTag.addEventListener("dblclick", function(eve) {
        let target = eve.target;

        if (target.titleID) return;

        let aTag   = document.getElementById('toTab');
        let slug   = target.getAttribute("slug");
        link       = "https://www.youtube-nocookie.com/embed/" + slug;
        aTag.href  = "https://www.youtube.com/watch?v=" + slug;
        document.getElementById('internalPlayer').src = link;
    });

    document.getElementById('video-list').appendChild(elm);
}
