import { redirect } from "next/navigation";
import { createClient } from "@/lib/supabase/server";
import { RouletteView } from "./roulette-view";

export default async function RoulettePage() {
  const supabase = await createClient();
  const {
    data: { user },
  } = await supabase.auth.getUser();

  if (!user) {
    redirect("/login");
  }

  const { data: members } = await supabase
    .from("profiles")
    .select("id, pseudo, avatar_url, role")
    .order("pseudo", { ascending: true });

  return (
    <div className="mx-auto w-full max-w-2xl px-4 py-8">
      <div className="mb-6 text-center">
        <h1 className="font-heading text-2xl tracking-[0.1em] text-gold-bright uppercase">
          La Roulette
        </h1>
        <p className="font-serif text-sm text-marble/60 italic">
          Que le sort désigne l&apos;élu.
        </p>
      </div>
      <RouletteView members={members ?? []} />
    </div>
  );
}
