import { route } from 'preact-router'
import { useEffect } from 'preact/hooks'
import { useCurrentUser } from '../hooks.jsx'

export const Admin = ({}) => {
    const [user] = useCurrentUser(user => {
        if (!user || user.role !== 'admin') {
            route('/', true)
        }
    })

    return (
        <main class="admin">
            <div class="logo">PHC / Problemi</div>
            <div class="subtitle">
                {user ? (
                    <>
                        Logged in as {user.role} @{user.username}
                    </>
                ) : (
                    <a href="/login">Login</a>
                )}
            </div>
        </main>
    )
}
