import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { useAuth } from '@/context/auth-context'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; // Form validation schema const formSchema = z.object({ email: z.string().email('Invalid email address'), password: z.string().min(6, 'Password must be at least 6 characters'), }); const LoginForm = () => { const { login } = useAuth(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { email: '', password: '', }, }); const onSubmit = async (values) => { try { setIsLoading(true); setError(''); await login({ email: values.email, password: values.password, }); } catch (error) { setError(error.message || 'Login failed. Please try again.'); } finally { setIsLoading(false); } }; return (