import { createClient } from "@/lib/supabase/server";
import { getCurrentProfile } from "@/lib/auth/profile";
import { listLeaguesForMaster } from "@/lib/services/leagues";
import { MasterLeaguesClient } from "@/components/master/master-leagues-client";

export default async function MasterLeaguesPage() {
  const supabase = await createClient();
  const ctx = await getCurrentProfile();
  const isGlobal = ctx?.profile?.portal_role === "league_master";

  const leagues = await listLeaguesForMaster(
    supabase,
    ctx!.user.id,
    !!isGlobal
  );

  return <MasterLeaguesClient initialLeagues={leagues} />;
}
