import { useNavigate } from "react-router-dom";
function Nav({
  authorized,
  setAuthorized,
}: {
  authorized: boolean;
  setAuthorized: Function;
}) {
  const navigate = useNavigate();
  const onClick = (path: string) => {
    navigate(path);
  };
  return (
    <div>
      <button onClick={() => onClick("/")}>Home</button>
      {authorized ? (
        <>
          <button onClick={() => onClick("/createlog")}>Create Log</button>
          <button
            onClick={() => {
              localStorage.removeItem("token");
              setAuthorized(false);
            }}
          >
            Logout
          </button>
        </>
      ) : (
        <>
          <button onClick={() => onClick("/login")}>Login</button>
          <button onClick={() => onClick("/register")}>Register </button>
        </>
      )}
    </div>
  );
}
export default Nav;
