import { useState, FormEvent } from 'react'; import { useNavigate } from 'react-router-dom'; import { toast } from 'sonner'; import { Lock } from 'lucide-react'; import { useAuth } from '@/hooks/useAuth'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; export default function LockScreen() { const navigate = useNavigate(); const { authStatus, login, setup, isLoginPending, isSetupPending } = useAuth(); const [pin, setPin] = useState(''); const [confirmPin, setConfirmPin] = useState(''); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); if (authStatus?.setup_required) { if (pin !== confirmPin) { toast.error('PINs do not match'); return; } if (pin.length < 4) { toast.error('PIN must be at least 4 characters'); return; } try { await setup(pin); toast.success('PIN created successfully'); navigate('/dashboard'); } catch (error: any) { toast.error(error.response?.data?.detail || 'Failed to create PIN'); } } else { try { await login(pin); navigate('/dashboard'); } catch (error: any) { toast.error(error.response?.data?.detail || 'Invalid PIN'); setPin(''); } } }; const isSetup = authStatus?.setup_required; return (