"use client";

import { signIn, signOut } from "next-auth/react";
import { SyntheticEvent } from "react";
import { Session } from "next-auth";
import { Button } from "@nextui-org/button";

interface SignInProps {
  session: Session | null;
}

export default function SignIn({ session }: SignInProps) {
  const handleSignIn = async (event: SyntheticEvent) => {
    event.preventDefault();
    await signIn("github");
  };

  const handleSignOut = async (event: SyntheticEvent) => {
    event.preventDefault();
    await signOut();
  };

  return session?.user ? (
    <form onSubmit={handleSignOut}>
      <Button type="submit">Sign out</Button>
    </form>
  ) : (
    <form onSubmit={handleSignIn}>
      <Button type="submit">Sign in</Button>
    </form>
  );
}
