import Link from "next/link";
import { redirect } from "next/navigation";

import { auth } from "@/auth";
import { getPostLoginRedirect } from "@/lib/post-login-redirect";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";

import { RegisterForm } from "./register-form";

export const metadata = { title: "Registrieren · Kita-Planer" };

export default async function RegisterPage() {
  const session = await auth();
  if (session?.user) {
    redirect(getPostLoginRedirect(session.user));
  }

  return (
    <div className="flex min-h-screen items-center justify-center bg-muted/30 px-4 py-12">
      <Card className="w-full max-w-md">
        <CardHeader className="space-y-2">
          <CardTitle>Kita kostenlos registrieren</CardTitle>
          <CardDescription>
            Lege deinen Account an. Im nächsten Schritt richtest du deine Kita ein.
          </CardDescription>
        </CardHeader>
        <CardContent className="space-y-4">
          <RegisterForm />
          <p className="text-center text-sm text-muted-foreground">
            Bereits einen Account?{" "}
            <Link href="/login" className="font-medium text-foreground underline">
              Anmelden
            </Link>
          </p>
        </CardContent>
      </Card>
    </div>
  );
}
