import '../styles/app.pcss';

import Alpine from 'alpinejs';
import { fetchCurrentUser, logoutRequest } from './components/game';

Alpine.data('navbar', () => ({
    isLoggedIn: false,
    user: null,

    async init() {
        this.user = await fetchCurrentUser();
        this.isLoggedIn = this.user !== null;
    },

    async logout() {
        await logoutRequest();
        this.user = null;
        this.isLoggedIn = false;
        window.location.href = '/login';
    }
}));

window.Alpine = Alpine;
Alpine.start();
