let audio = new Audio();
var request = new XMLHttpRequest();
var count = 0;
function Main() {

    return {
        DiscordGuildId: '1184970607335591968', // Also know as Discord server ID [ENABLE DISCORD WIDGET ON YOUR DISCORD SERVER!]
        DiscordInviteLink: 'https://discord.com/invite/4d3NCeH3hW', // Insert your Discord invite link here.
        memberCount: 0,
        musicAutoplay: true, // Set this to true if you want the music to autoplay
        musicVolume: 0.1, // Set the volume that you like (0 = 0% ; 0.5 = 50% ; 1 = 100%)
        buttons: [
            { label: 'Forside', selected: true },
            { label: 'Nyheder', selected: false },
            { label: 'Team', selected: false },
        ],
        musicList: [
            { label: 'Out Of My Head', author: 'HUTS, y_x', src: 'audio/head.mp3' },
            { label: 'Birds', author: 'Imagine Dragons', src: 'audio/birds.mp3' },
            { label: 'Empire State Of Mind', author: 'JAY-Z, Alicia Keys', src: 'audio/empire.mp3' },
        ],
        // No touching here!!!!
        isMusicPlaying: false,
        musicOpen: false,
        currentSong: 0,
        listen() {
            if (this.musicAutoplay) {
                setTimeout(() => { this.play(); }, 100);
            }
            
            request.open('GET', 'https://discordapp.com/api/guilds/' + this.DiscordGuildId + '/widget.json', true);
            request.onload = function () {
                if (request.status >= 200 && request.status < 400) {
                    var data = JSON.parse(request.responseText);
                    count = data.presence_count;
                }
            };
            request.onerror = function () {
            };
            request.send();
            setTimeout(() => { this.memberCount = count; }, 1000);
        },
        selectBtn(select) {
            this.buttons.forEach(function (button) {
                button.selected = false;
            });
            return true;
        },
        play() {
            audio.src = this.musicList[this.currentSong].src;
            audio.load();
            audio.play();
            audio.volume = this.musicVolume;
            this.isMusicPlaying = true;
        },
        pause() {
            audio.pause()
            this.isMusicPlaying = false;
        },
        next() {
            if (this.isMusicPlaying) {
                audio.pause()
            }
            if (this.currentSong < this.musicList.length - 1) {
                this.currentSong++;
            } else {
                this.currentSong = 0;
            }
            audio.src = this.musicList[this.currentSong].src;
            audio.load();
            audio.play();
            this.isMusicPlaying = true;
        },
        prev() {
            if (this.isMusicPlaying) {
                audio.pause()
            }
            if (this.currentSong != 0) {
                this.currentSong = this.currentSong - 1;
            } else {
                this.currentSong = this.musicList.length - 1;
            }
            audio.src = this.musicList[this.currentSong].src;
            audio.load();
            audio.play();
            this.isMusicPlaying = true;
        },
    }
}

function copyToClipboard(text) {
    const input = document.createElement('input');
    input.value = text;
    document.body.appendChild(input);
    input.select();
    document.execCommand('copy');
    document.body.removeChild(input);

    const notification = document.createElement('div');
    notification.classList.add('notification');
    notification.textContent = `Discord ${text} was copied to clipboard`;
    document.body.appendChild(notification);
    notification.style.opacity = 1;
    setTimeout(() => {
        notification.style.opacity = 0;
        setTimeout(() => {
            document.body.removeChild(notification);
        }, 300);
    }, 3000);
}


$(document).ready(function () {
    var movementStrength = 25;
    var height = movementStrength / $(window).height();
    var width = movementStrength / $(window).width();
    $(document).mousemove(function (e) {
        var pageX = e.pageX - ($(window).width() / 2);
        var pageY = e.pageY - ($(window).height() / 2);
        var newvalueX = width * pageX * -1 - 25;
        var newvalueY = height * pageY * -1 - 50;
        $('.bg1').css("background-position", newvalueX + "px     " + newvalueY + "px");
    });

    const moveCursor = (e) => {
        const mouseY = e.pageY;
        const mouseX = e.pageX;

        $('#cursor').css('transform', `translate3d(${mouseX}px, ${mouseY}px, 0)`)

    }
    window.addEventListener('mousemove', moveCursor)
});

