"use client"

import Link from "next/link"
import { AuthFlowPage } from "@/components/auth/auth-flow-page"
import { AUTH_FLOW_SLUGS } from "@/lib/auth/auth-flow-slugs"

type LoginPageContentProps = {
  returnTo?: string
  error?: string | null
}

export function LoginPageContent({
  returnTo = "/mail/inbox",
  error = null,
}: LoginPageContentProps) {
  const signupHref = `/signup?returnTo=${encodeURIComponent(returnTo)}`
  const forgotPasswordHref = `/forgot-password?returnTo=${encodeURIComponent(returnTo)}`
  const oidcFallbackHref = `/api/auth/login?returnTo=${encodeURIComponent(returnTo)}`

  return (
    <AuthFlowPage
      slug={AUTH_FLOW_SLUGS.authentication}
      flowQuery={undefined}
      defaultTitle="Connexion"
      defaultDescription="Connecte-toi avec ton compte UltiSpace pour accéder à ta suite."
      successTitle="Connexion réussie"
      successDescription="Redirection vers votre espace…"
      successActionLabel="Continuer"
      successHref={returnTo}
      bridgeAuthentication
      returnTo={returnTo}
      initialError={error}
      footer={
        <div className="flex w-full flex-col gap-3 text-center text-sm text-muted-foreground">
          <p>
            <a className="font-medium text-primary underline" href={oidcFallbackHref}>
              Connexion via redirect UltiSpace
            </a>
          </p>
          <p>
            Pas encore de compte ?{" "}
            <Link className="font-medium text-primary underline" href={signupHref}>
              Créer un compte
            </Link>
          </p>
          <p>
            <Link className="font-medium text-primary underline" href={forgotPasswordHref}>
              Mot de passe oublié ?
            </Link>
          </p>
        </div>
      }
    />
  )
}
