import Link from 'next/link';

interface IracingAuthPageProps {
  searchParams: Promise<{
    returnTo?: string;
  }>;
}

export default async function IracingAuthPage({ searchParams }: IracingAuthPageProps) {
  const params = await searchParams;
  const returnTo = params.returnTo ?? '/dashboard';
  const startUrl = `/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`;

  return (
    <main className="min-h-screen flex items-center justify-center bg-deep-graphite">
      <div className="max-w-md w-full px-6 py-8 bg-iron-gray/80 rounded-lg border border-white/10 shadow-xl">
        <h1 className="text-2xl font-semibold text-white mb-4">Authenticate with iRacing</h1>
        <p className="text-sm text-gray-300 mb-6">
          Connect a demo iRacing identity to explore the GridPilot dashboard with seeded data.
        </p>
        <Link
          href={startUrl}
          className="inline-flex items-center justify-center px-4 py-2 rounded-md bg-primary-blue text-sm font-medium text-white hover:bg-primary-blue/90 transition-colors w-full"
        >
          Start iRacing demo login
        </Link>
      </div>
    </main>
  );
}