import { redirect } from "next/navigation";
import { auth } from "@/auth";
import { authentikLoginAction } from "./actions";
import { LoginForm } from "./login-form";
import { Button } from "@/components/ui/button";
import { t } from "@/lib/i18n/de";

// Anmeldeseite (öffentlich, in der Middleware-Allowlist). Bietet Authentik-OIDC
// (Platform-Admins) und lokalen Credentials-Login (Wehr-Konten).
export default async function AnmeldenPage() {
  // Bereits angemeldete Nutzer nicht erneut anmelden lassen.
  const session = await auth();
  if (session?.user) redirect("/");

  return (
    <div>
      <h1 className="font-display text-xl text-navy">{t("auth.anmelden")}</h1>
      <p className="mt-1 text-sm text-anthrazit/70">{t("auth.erforderlich")}</p>

      <form action={authentikLoginAction} className="mt-6">
        <Button type="submit" variant="primary" className="w-full">
          {t("auth.mitAuthentik")}
        </Button>
      </form>

      <p className="mt-4 text-center text-xs text-anthrazit/60">
        {t("auth.oderLokal")}
      </p>

      <LoginForm />
    </div>
  );
}
