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";

async function Page() {
  const sessionPlayer = await api.player.getBySession();
  if (!sessionPlayer) return redirect(appRoutes.signIn);
  const lobby = sessionPlayer ? await api.lobby.getCurrentLobby() : null;
  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} sessionPlayer={sessionPlayer} />;
}

export default Page;
