import { getUser } from "@/auth/auth";
import { getUserInfo } from "@/ldap";
import AboutMe from "./AboutMe";
import { redirect } from "next/navigation";
import { DiscordAuthProvider } from "@/auth/discord";
import { GitHubAuthProvider } from "@/auth/github";
import { AuthProviderState } from "@/auth/AuthProvider";

// this sucks but i'm lazy
const discordFallback: AuthProviderState = {
  name: "Discord",
  connected: false
};

const githubFallback: AuthProviderState = {
  name: "GitHub",
  connected: false
};

export default async function Page() {
  const user = await getUser();
  if (!user) redirect("/login");

  const info = await getUserInfo(user);
  if (info === null) redirect("/register");

  const discord = await user.getDiscord();
  const discordState = (await discord?.getState()) ?? discordFallback;
  const github = await user.getGitHub();
  const githubState = (await github?.getState()) ?? githubFallback;

  const providers = [discordState, githubState];

  // not sure how to feel about passing it like this
  return <AboutMe info={info} providers={providers} />;
}
