import { useState } from 'react'; import { Link, useNavigate } from 'react-router'; import { Shield } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card'; import { useAuthStore } from '@/stores/auth'; import { ApiError } from '@/lib/api'; export function LoginPage() { const navigate = useNavigate(); const login = useAuthStore((s) => s.login); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { await login(email, password); navigate('/'); } catch (err) { if (err instanceof ApiError) { setError(err.status === 401 ? 'Invalid email or password' : 'An error occurred'); } else { setError('An error occurred'); } } finally { setLoading(false); } }; return (