import { useState } from 'react'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { Checkbox } from '../ui/checkbox'; import { AlertCircle, Copy, Check, Eye, EyeOff } from 'lucide-react'; import { mockUsers } from '../../lib/mock-data'; import { toast } from 'sonner'; interface LoginPageProps { onLogin: (email: string, password: string) => void; } export function LoginPage({ onLogin }: LoginPageProps) { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [rememberMe, setRememberMe] = useState(false); const [error, setError] = useState(''); const [showForgotPassword, setShowForgotPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); const [copiedIndex, setCopiedIndex] = useState(null); const copyToClipboard = async (text: string, index: number) => { try { // Try modern clipboard API first if (navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(text); setCopiedIndex(index); setTimeout(() => setCopiedIndex(null), 2000); return; } } catch (err) { // Clipboard API blocked, try fallback method } // Fallback method for older browsers or blocked clipboard try { const textArea = document.createElement('textarea'); textArea.value = text; textArea.style.position = 'fixed'; textArea.style.left = '-999999px'; textArea.style.top = '-999999px'; document.body.appendChild(textArea); textArea.focus(); textArea.select(); const successful = document.execCommand('copy'); document.body.removeChild(textArea); if (successful) { setCopiedIndex(index); setTimeout(() => setCopiedIndex(null), 2000); } } catch (err) { // Both methods failed - silently ignore } }; const quickLogin = async (userEmail: string, userPassword: string) => { setEmail(userEmail); setPassword(userPassword); setError(''); setIsLoading(true); try { await onLogin(userEmail, userPassword); } catch (err: any) { const msg = err.response?.data?.message || err.message || 'Auto-login failed'; setError(msg); toast.error(msg); } finally { setIsLoading(false); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (isLoading) return; setError(''); if (!email || !password) { setError('Please enter both email and password'); return; } setIsLoading(true); try { await onLogin(email, password); } catch (err: any) { const msg = err.response?.data?.message || err.message || 'Login failed'; setError(msg); toast.error(msg); } finally { setIsLoading(false); } }; const handleForgotPassword = (e: React.FormEvent) => { e.preventDefault(); // Mock password reset alert('Password reset link sent to ' + email); setShowForgotPassword(false); }; return (
{/* Background decorative elements */}
{/* Left side - Login Form */}
{/* Logo and Header */}

Royal Enfield

Dealership Onboarding System

{/* Login Form */}
{!showForgotPassword ? (
setEmail(e.target.value)} className="w-full" disabled={isLoading} />
setPassword(e.target.value)} className="no-native-password-reveal w-full pr-10" autoComplete="current-password" disabled={isLoading} />
setRememberMe(checked as boolean)} disabled={isLoading} />
{error && (
{error}
)}
Or
) : (

Reset Password

Enter your email to receive a password reset link

setEmail(e.target.value)} required className="w-full" />
)}
{/* Footer */}

© 2025 Royal Enfield. All rights reserved.

{/* Right side - Test Credentials */}

Test User Credentials

Click on any user to auto-login

{mockUsers.map((user, index) => (
quickLogin(user.email, user.password)} >
{user.role}

{user.name}

Email:

{user.email}

Password:

{user.password}

Click to login as {user.role}

))}
); }