import { useState } from 'react'; interface LoginResult { success: boolean; isAdmin: boolean; message: string; } interface SecretLoginProps { onLogin: (username: string, code: string) => Promise | LoginResult; onBack: () => void; onSuccess: (isAdmin: boolean) => void; } export function SecretLogin({ onLogin, onBack, onSuccess }: SecretLoginProps) { const [username, setUsername] = useState(''); const [code, setCode] = useState(''); const [message, setMessage] = useState(''); const [messageType, setMessageType] = useState<'error' | 'success'>('error'); const [loading, setLoading] = useState(false); const [attempts, setAttempts] = useState(0); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!username.trim() || !code.trim()) { setMessage('Please enter both username and access code.'); setMessageType('error'); return; } setLoading(true); try { // Await supports both async and sync onLogin const result = await Promise.resolve(onLogin(username.trim(), code.trim())); setMessage(result.message); setMessageType(result.success ? 'success' : 'error'); if (result.success) { setTimeout(() => { onSuccess(result.isAdmin); }, 800); } else { setAttempts(prev => prev + 1); } } catch { setMessage('An error occurred. Please try again.'); setMessageType('error'); } finally { setLoading(false); } }; return (
{/* Back button disguised */}
{/* Lock icon */}

Restricted Access

Enter your credentials to continue

setUsername(e.target.value)} className="w-full px-4 py-3 bg-gray-800 border border-gray-700 rounded-xl text-white placeholder-gray-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 transition-colors" placeholder="Enter your name" autoComplete="off" />
setCode(e.target.value)} className="w-full px-4 py-3 bg-gray-800 border border-gray-700 rounded-xl text-white placeholder-gray-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 transition-colors" placeholder="Enter access code" autoComplete="off" />
{message && (
{message}
)}
{attempts >= 3 && (

Multiple failed attempts detected. All attempts are logged.

)}

All login attempts are recorded and monitored.

); }