import LoginForm from "@/components/auth/LoginForm";
import { parseLoginParams } from "@/lib/frontend/authRedirect";

/**
 * /login (RHL-020)
 *
 * Server Component:
 * - Parses query params on the server (reason/next).
 * - Renders a Client Component (LoginForm) for the actual interaction.
 *
 * Query params:
 * - reason=expired | logged-out
 * - next=/some/internal/path
 */
export default async function LoginPage({ searchParams }) {
	// In newer Next versions, searchParams can be async; awaiting is safe.
	const resolvedSearchParams = await searchParams;

	// Parse + sanitize using shared pure helper.
	const { reason, next } = parseLoginParams(resolvedSearchParams);

	return (
		<div className="w-full space-y-6">
			<div className="space-y-2 text-center">
				<h1 className="text-2xl font-semibold tracking-tight">
					RHL Lieferscheine
				</h1>
				<p className="text-sm text-muted-foreground">
					Bitte melden Sie sich an, um fortzufahren.
				</p>
			</div>

			<LoginForm reason={reason} nextPath={next} />

			<p className="text-center text-xs text-muted-foreground">
				Bei Fragen wenden Sie sich an Ihren Administrator.
			</p>
		</div>
	);
}
