import { useEffect, useState } from 'react' import { ArrowRight, Eye, EyeOff, Globe, Loader2, LockKeyhole, Sparkles, UserRound, } from 'lucide-react' import Modal from './Modal' import Button from './Button' export default function AuthDialogPanel({ open, mode, onModeChange, onClose, onLogin, onRegister, onGoogleLogin, pending, }) { const [name, setName] = useState('') const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [showPassword, setShowPassword] = useState(false) const isRegister = mode === 'register' const submitLabel = isRegister ? 'Create account' : 'Sign in' useEffect(() => { setError('') setShowPassword(false) }, [mode, open]) const submit = async (event) => { event.preventDefault() setError('') if (!username || !password || (isRegister && !name.trim())) { setError('Fill all fields.') return } try { if (isRegister) { await onRegister({ username, name: name.trim(), password }) } else { await onLogin({ username, password }) } } catch (authError) { setError(authError.message || 'Authentication failed.') } } return ( { if (!next) onClose() }} size="sm" title={isRegister ? 'Create account' : 'Sign in'} className="auth-panel border-border bg-card" > onModeChange('login')} className={`rounded-lg px-4 py-2 text-sm font-medium transition ${ mode === 'login' ? 'bg-background text-foreground' : 'text-muted-foreground hover:text-foreground' }`} > Login onModeChange('register')} className={`rounded-lg px-4 py-2 text-sm font-medium transition ${ mode === 'register' ? 'bg-background text-foreground' : 'text-muted-foreground hover:text-foreground' }`} > Register Google {isRegister ? ( ) : null} Password setPassword(event.target.value)} placeholder="Password" autoComplete={isRegister ? 'new-password' : 'current-password'} /> setShowPassword((current) => !current)} className="rounded-lg p-1 text-muted-foreground transition hover:bg-secondary hover:text-foreground" aria-label={showPassword ? 'Hide password' : 'Show password'} > {showPassword ? : } {error ? ( {error} ) : null} {pending ? : null} {submitLabel} ) } function AuthField({ icon: Icon, label, value, onChange, placeholder, autoComplete, autoFocus = false, }) { return ( {label} onChange(event.target.value)} placeholder={placeholder} autoComplete={autoComplete} autoFocus={autoFocus} /> ) }