'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { useRouter, useSearchParams } from 'next/navigation'; import { motion, AnimatePresence, useReducedMotion } from 'framer-motion'; import { Gamepad2, Flag, ArrowRight, Shield, Link as LinkIcon, User, Trophy, BarChart3, CheckCircle2, } from 'lucide-react'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import Heading from '@/components/ui/Heading'; import { useAuth } from '@/lib/auth/AuthContext'; interface ConnectionStep { id: number; icon: typeof Gamepad2; title: string; description: string; } const CONNECTION_STEPS: ConnectionStep[] = [ { id: 1, icon: Gamepad2, title: 'Connect iRacing', description: 'Authorize GridPilot to access your profile', }, { id: 2, icon: User, title: 'Import Profile', description: 'We fetch your racing stats and history', }, { id: 3, icon: Trophy, title: 'Sync Achievements', description: 'Your licenses, iRating, and results', }, { id: 4, icon: BarChart3, title: 'Ready to Race', description: 'Access full GridPilot features', }, ]; const BENEFITS = [ 'Automatic profile creation with your iRacing data', 'Real-time stats sync including iRating and Safety Rating', 'Import your racing history and achievements', 'No manual data entry required', 'Verified driver identity in leagues', ]; export default function IracingAuthPage() { const router = useRouter(); const searchParams = useSearchParams(); const { session } = useAuth(); const returnTo = searchParams.get('returnTo') ?? '/dashboard'; const startUrl = `/auth/iracing/start?returnTo=${encodeURIComponent(returnTo)}`; const shouldReduceMotion = useReducedMotion(); const [isMounted, setIsMounted] = useState(false); const [activeStep, setActiveStep] = useState(0); const [isHovering, setIsHovering] = useState(false); // Check if user is already authenticated useEffect(() => { if (session) { router.replace('/dashboard'); } }, [session, router]); useEffect(() => { setIsMounted(true); }, []); useEffect(() => { if (!isMounted || isHovering) return; const interval = setInterval(() => { setActiveStep((prev) => (prev + 1) % CONNECTION_STEPS.length); }, 2500); return () => clearInterval(interval); }, [isMounted, isHovering]); return (
{/* Background Pattern */}
{/* Header */}
Connect Your iRacing Account

Link your iRacing profile for automatic stats sync and verified driver identity.

{/* Background accent */}
{/* Connection Flow Animation */}
setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} >

Connection Flow

{/* Steps */}
{CONNECTION_STEPS.map((step, index) => { const isActive = index === activeStep; const isCompleted = index < activeStep; const StepIcon = step.icon; return ( setActiveStep(index)} className="flex flex-col items-center text-center flex-1 cursor-pointer" whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} > {isCompleted ? ( ) : ( )}

{step.title}

); })}
{/* Active Step Description */}

{CONNECTION_STEPS[activeStep]?.description}

{/* Benefits List */}

What you'll get:

    {BENEFITS.map((benefit, index) => (
  • {benefit}
  • ))}
{/* Connect Button */} {/* Trust Indicators */}
Secure OAuth connection
Read-only access
{/* Alternative */}

Don't have iRacing?{' '} Create account with email

{/* Footer */}

GridPilot only requests read access to your iRacing profile.
We never access your payment info or modify your account.

); }