'use client'; import { useState, FormEvent } from 'react'; import { useRouter } from 'next/navigation'; import { Lock, User, Loader2 } from 'lucide-react'; import { motion } from 'framer-motion'; import Image from 'next/image'; export default function AdminLogin() { const router = useRouter(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { const response = await fetch('/api/admin/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username, password }), }); const data = await response.json(); if (!response.ok) { setError(data.error || 'Login failed'); setIsLoading(false); return; } // Successful login - redirect to dashboard router.push('/admin/dashboard'); } catch (err) { setError('Network error. Please try again.'); setIsLoading(false); } }; return (