import { useRouter } from 'next/router'
import Link from 'next/link'

import { useSession } from 'next-auth/react'

import User from './user'

const pathNameLabelMap = {
  '/login': 'Login',
  '/admin': 'Buchungsübersicht',
  '/admin/booking/[uuid]': 'Buchung Bearbeiten',
  '/admin/booking/[uuid]/bill': 'Buchung Rechnungsstellung',
  '/book': 'Buchungsanfrage',
  '/booking/[uuid]': 'Ihre Buchung',
  '/booking/[uuid]/stored': 'Buchungsanfrage angenommen',
}

function getPathNameMap(route: string) {
  return pathNameLabelMap[route]
}

export default function Navigation() {
  const { data, status } = useSession()
  const router = useRouter()

  const pathname = router.pathname
  if (pathname.length === 0 || pathname === '/') {
    return null
  }

  const pathLabel = getPathNameMap(pathname)

  return (
    <div className="flex flex-row items-center px-3 py-1 text-white text-base bg-blue-400 rounded-b-sm">
      <>
        <h2 className="mx-1">
          <span className="font-extrabold">{pathLabel}</span>
        </h2>
        {status === 'authenticated' && data.user.email && (
          <Link href="/admin" className="text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium">
              Buchungen
          </Link>
        )}
        <div className="flex-grow" />
        <User />
      </>
    </div>
  )
}
