import { h, type FunctionComponent } from 'preact'
import cn from 'classnames'

import { useCurrentUser } from '../contexts/current_user.ts'
import s from './current_user.module.scss'

const CurrentUser: FunctionComponent<{ className?: string }> = ({ className }) => {
  const { user } = useCurrentUser()

  return user ? (
    <div className={cn(s.base, className)}>
      <div className={s.email}>{user.email}</div>

      <div className={s.links}>
        <a href='/auth/logout' data-native>
          Logout
        </a>
      </div>
    </div>
  ) : (
    <div className={cn(s.base, className)}>
      <p>You are not logged in</p>

      <div className={s.links}>
        <a href='/admin/login'>Login</a>
        <a href='/admin/register'>Register</a>
      </div>
    </div>
  )
}

export default CurrentUser
