// Enter page: the threshold. Gothic auth panel floating in CSS fog — // toggles between Reconnect (login) and First contact (register), and // steps the medium through to the séance on success. import { useState } from 'react' import type { FormEvent } from 'react' import { Navigate, useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useAuth } from '../state/auth' import './EnterPage.css' type EnterMode = 'login' | 'register' export function EnterPage() { const { t } = useTranslation() const { user, login, register } = useAuth() const navigate = useNavigate() const [mode, setMode] = useState('login') const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState(null) const [busy, setBusy] = useState(false) // Already seated at the table — no need to knock again. if (user) { return } const switchMode = (next: EnterMode) => { setMode(next) setError(null) } const handleSubmit = async (event: FormEvent) => { event.preventDefault() if (busy) return setError(null) setBusy(true) try { if (mode === 'register') { await register(username, password) } else { await login(username, password) } navigate('/seance') } catch (err) { setError(err instanceof Error ? err.message : String(err)) setBusy(false) } } return (