import Cookies from "js-cookie";
import Link from "next/link";

function Navbar(): JSX.Element {
  const isLoggedIn = !!Cookies.get("mentorenwahl_bearer");

  function handleLogout(event: MouseEvent): void {
    event.preventDefault();
    Cookies.remove("mentorenwahl_bearer");
  }

  return (
    <nav>
      <ul>
        <li>
          {isLoggedIn ? (
            <button onClick={handleLogout as any}>Logout</button>
          ) : (
            <Link href="/login" passHref>
              <button>Login</button>
            </Link>
          )}
        </li>
      </ul>
    </nav>
  );
}

export default Navbar;
