import { requireAuth } from "@/lib/session";
import { db } from "@/lib/db";
import TeamBuilder from "./TeamBuilder";

export default async function TeamPage() {
  const session = await requireAuth();
  const userId = (session.user as any).id;

  const team = await db.team.findUnique({
    where: { userId },
    include: {
      players: {
        include: { player: { include: { country: true } } },
      },
    },
  });

  const allPlayers = await db.player.findMany({
    include: { country: true },
    orderBy: { totalPoints: "desc" },
  });

  return <TeamBuilder team={team} allPlayers={allPlayers} />;
}
