import { redirect } from "next/navigation";

import { getSignupMode } from "@/lib/settings";
import { SignupForm } from "@/components/auth/signup-form";
import { SignupMode } from "@/lib/generated/prisma/enums";

// Whether sign-ups are open at all depends on live, admin-editable
// settings -- this can't be prerendered once at build time.
export const dynamic = "force-dynamic";

export default async function SignupPage() {
  const signupMode = await getSignupMode();

  // Disables the URL, not just the messaging that links to it -- visiting
  // /signup directly while closed bounces to /login instead of rendering
  // a dead form. signup() (the Server Action) refuses new accounts too.
  if (signupMode === SignupMode.CLOSED) redirect("/login");

  return <SignupForm mode={signupMode} />;
}
