<template>
    <div class="config-panel hidden">
        <div class="config-panel-content">
            <span class="config-panel-label">Welcome </span>
            <span v-if="user">
                {{ user.name + " " + user.surname }}
            </span> 
            <!-- <button @click="redirectProject()" class="p-button p-button-outlined">Projects</button> -->
            <!-- <button @click="auth.logout()" class="p-button p-button-outlined">Logout</button> -->
            <button @click="logout()" class="p-button p-button-outlined">Logout</button>

        </div>
    </div>
</template>

<script setup>

import { useAuth } from '@websanova/vue-auth/src/v3.js';
import { computed } from 'vue';
import { useRouter } from 'vue-router';
import { ScenarioStore } from '@/stores/ScenarioStore';


const auth = useAuth();
const user = computed(() => auth.user());
const  router = useRouter();
const scenario_store = ScenarioStore();


function redirectProject() {
    router.push('/projects'); // Specifica il percorso per la pagina "Projects"
}

function logout() {
    auth.logout().then(() => {
        scenario_store.resetStore();
        router.push('/auth/login');
    }).catch(err => {
        console.error("Errore durante il logout:", err);
    });
}

</script>
