"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Checkbox } from "@/components/ui/checkbox"; import { Eye, EyeOff, Loader2 } from "lucide-react"; import { toast } from "sonner"; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!email || !password) { toast.error("Please enter email and password"); return; } setLoading(true); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { toast.error(data.error || "Login failed"); return; } toast.success("Login successful"); window.location.href = "/"; } catch { toast.error("An error occurred"); } finally { setLoading(false); } } return (