/**
 * Login Page
 *
 * RSC composition pattern:
 * 1. PageQuery executes to get ViewData
 * 2. Client component renders with ViewData
 */

import { LoginPageQuery } from '@/lib/page-queries/auth/LoginPageQuery';
import { LoginClient } from './LoginClient';
import { AuthError } from '@/ui/AuthError';

export default async function LoginPage({
  searchParams,
}: {
  searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
  // Execute PageQuery
  const params = await searchParams;
  const queryResult = await LoginPageQuery.execute(params);

  if (queryResult.isErr()) {
    return <AuthError action="login" />;
  }

  const viewData = queryResult.unwrap();

  // Render client component with ViewData
  return <LoginClient viewData={viewData} />;
}