const infoUsername = getID("infoUsername")
const infoUserimage = getID("infoUserimage")
const infoDisplayname = getID("infoDisplayname")
const views = getID("views")

// User Request

const REQ_user = get("USERINFO")

REQ_user.then((ANS_user) => {
    infoUserimage.src = ANS_user.picture
    infoUsername.innerHTML = ANS_user.username
    infoDisplayname.innerHTML = ANS_user.display_name

    const permissions = ANS_user.permission

    const AvailableViews = new Array()

    permissions.forEach((permValue) => {
        
         if(permValue == "FILES_EXPLORER") {
            AvailableViews.push(`<div class="view">
            <span class="view-image"><i class="fa-solid fa-folder"></i></span>
            <p class="view-text">Gestionnaire de fichiers</p>
        </div>`)
         }
         if(permValue == "SERVICES") {
            AvailableViews.push(`<div class="view">
            <span class="view-image"><i class="fa-solid fa-layer-group"></i></span>
            <p class="view-text">Gestion des services</p>
        </div>`)
         }
         if(permValue == "SERVERS") {
            AvailableViews.push(`<div class="view">
            <span class="view-image"><i class="fa fa-server"></i></span>
            <p class="view-text">Gestion des serveurs</p>
          </div>`)
         }
         if(permValue == "PIPELINES") {
            AvailableViews.push(` <div class="view">
            <span class="view-image"><i class="fa-brands fa-jenkins"></i></span>
            <p class="view-text">Gestion des pipelines</p>
          </div>`)
         }
         if(permValue == "METRICS") {
            AvailableViews.push(` <div class="view">
            <span class="view-image"><i class="fa-solid fa-square-poll-vertical"></i></span>
            <p class="view-text">Web Metrics</p>
          </div>`)
         }
         if(permValue == "USERS") {
            AvailableViews.push(` <div class="view">
            <span class="view-image"><i class="fa fa-users"></i></span>
            <p class="view-text">Gestion des utilisateurs</p>
          </div>`)
         }
         if(permValue == "LINKS") {
            AvailableViews.push(` <div class="view">
            <span class="view-image"><i class="fa-solid fa-link"></i></span>
            <p class="view-text">Générateur de lien</p>
          </div>`)
         }
         if(permValue == "SETTINGS") {
            AvailableViews.push(` <div class="view">
            <span class="view-image"><i class="fa fa-gear"></i></span>
            <p class="view-text">Paramètres</p>
          </div>`)
         }

        
    })
    

    if(AvailableViews.join("") == "") {

        AvailableViews.push("<p class='yellow'><i class='fa-solid fa-warning'></i> Aucune permission ne semble vous êtes accordée<br>Demandez à Raphix afin de résoudre ce problème</p>")
        views.classList.remove("views-box")
    } else {

        views.classList.add("views-box")
    }

    views.innerHTML = AvailableViews.join("")

})

