import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext';
import { Plane } from 'lucide-react';

export function Login() {
  const { isAuthenticated, loginWithRedirect } = useAuth();
  const navigate = useNavigate();

  useEffect(() => {
    if (isAuthenticated) {
      navigate('/dashboard');
    }
  }, [isAuthenticated, navigate]);

  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-primary/5 via-background to-primary/10">
      <div className="max-w-md w-full bg-card border border-border rounded-lg shadow-xl p-8">
        <div className="text-center mb-8">
          <div className="inline-block p-3 bg-primary/10 rounded-full mb-4">
            <Plane className="h-12 w-12 text-primary" />
          </div>
          <h1 className="text-3xl font-bold text-foreground mb-2">
            VIP Coordinator
          </h1>
          <p className="text-muted-foreground">
            Transportation logistics and event coordination
          </p>
        </div>

        <button
          onClick={() => loginWithRedirect()}
          className="w-full bg-primary text-primary-foreground py-3 px-4 rounded-lg font-medium hover:bg-primary/90 transition-colors"
        >
          Sign In with Auth0
        </button>

        <div className="mt-6 text-center text-sm text-muted-foreground">
          <p>First user becomes administrator</p>
          <p>Subsequent users require admin approval</p>
        </div>
      </div>
    </div>
  );
}
