import { useUser } from '../../user/userStore.ts'
import NavButton from '../../../components/buttons/NavButton.tsx'
import { useLocation } from 'react-router-dom'

export default function AuthNavButtons() {
  const { user } = useUser()

  const { pathname } = useLocation()

  const redirectQuery = new URLSearchParams()
  redirectQuery.set('t', pathname)

  const loggedIn = user != null

  if (loggedIn) {
    return (
      <>
        <NavButton to="/logout">logout</NavButton>
      </>
    )
  } else {
    const search = redirectQuery.toString()
    return (
      <>
        <NavButton to={{ pathname: '/login', search }}>login</NavButton>
        <NavButton to={{ pathname: '/signup', search }}>register</NavButton>
      </>
    )
  }
}
