import { useSession, signOut } from 'next-auth/react'
import Link from 'next/link'

export default function User() {
  const { data, status } = useSession()

  if (status === 'loading' || !data?.user?.email) {
    return null
  }

  return (
    <>
      <Link
        href="/admin"
        className="text-base font-medium text-gray-500 hover:text-gray-900"
      >
        Admin
      </Link>
      <div className="font-extrabold bg-red-400 px-2 py-1 mr-3 rounded-xs">
        {data.user.email}
      </div>
      <button onClick={() => signOut()} className="btn btn-blue">
        Logout
      </button>
    </>
  )
}
