'use client'

import { HomeButton } from '@/app/components/HomeButton'
import { DiscordButton } from '@/app/components/DiscordButton'
import { getCookie } from '@/util/cookie'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'

export default function AccountLoginPage () {
  const [loading, setLoading] = useState<boolean>(true)
  const router = useRouter()

  useEffect(() => {
    const token = getCookie('accountToken', '-1')
    if (token === '-1') {
      router.push('/account/login')
    } else setLoading(false)
  }, [router])

  return (
    <div className='box'>
      <HomeButton />
      <DiscordButton />
      <p className={`px-8 -my-2 text-center`}>
        {loading
          ? 'Loading...'
          : 'Nothing on this page yet! You are logged in as ' +
            getCookie('accountUsername', 'N/A') +
            '.'}
      </p>
    </div>
  )
}
