import React from "react";
import { api } from "@/trpc/server";
import CreateLobbyDialog from "@/app/_components/lobby/create-lobby-dialog";
import { Button } from "@/components/ui/button";
import LobbyPage from "@/app/_components/lobby/lobby-page";
import { redirect } from "next/navigation";
import { appRoutes } from "@/config/app.routes";
import { auth } from "@/server/auth";

async function Page() {
  const session = await auth();
  if (!session?.user) return redirect(appRoutes.signIn);
  const lobby = await api.lobby.getCurrentLobby();
  if (!lobby)
    return (
      <div className="flex w-full gap-4">
        <CreateLobbyDialog className="grow" />
        <Button
          variant={"party"}
          size={"xxl"}
          className="container-bg bg-border/10"
        >
          Placeholder
        </Button>
      </div>
    );
  return <LobbyPage initialLobby={lobby} />;
}

export default Page;
