import { useState } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { Hotel } from 'lucide-react' export function Login() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const navigate = useNavigate() const location = useLocation() const from = (location.state as { from?: string })?.from || '/' async function submit(e: React.FormEvent) { e.preventDefault() setLoading(true) setError('') try { const res = await fetch('/api/auth/login', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }) if (res.ok) navigate(from, { replace: true }) else setError('Invalid email or password') } catch { setError('Connection error — please try again') } finally { setLoading(false) } } return (