"use client";import { useState } from "react";import { useRouter } from "next/navigation";import Link from "next/link";import { LockKeyhole } from "lucide-react";
export default function Login(){const router=useRouter(),[error,setError]=useState(""),[loading,setLoading]=useState(false);async function submit(e:React.FormEvent<HTMLFormElement>){e.preventDefault();setLoading(true);const body=Object.fromEntries(new FormData(e.currentTarget));const r=await fetch("/api/admin/auth",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(body)});const x=await r.json() as {error?:string};if(!r.ok){setError(x.error||"Sign in failed");setLoading(false);return}router.push("/admin")}return <main className="admin-login"><section><Link className="brand" href="/"><i>Ω</i><div><b>OMEGA FIRE</b><small>CONFERENCE ADMIN</small></div></Link><div className="login-card"><LockKeyhole/><h1>Welcome back</h1><p>Sign in to manage the conference.</p><form onSubmit={submit}><div className="field"><label>Email address</label><input name="email" type="email" required/></div><div className="field"><label>Password</label><input name="password" type="password" minLength={12} required/></div><details><summary>First administrator setup</summary><div className="field"><label>Your name</label><input name="name"/></div><div className="field"><label>One-time setup token</label><input name="setupToken" type="password"/></div></details>{error&&<div className="status error">{error}</div>}<button className="btn btn-red" disabled={loading}>{loading?"Signing in...":"Secure sign in"}</button></form></div></section></main>}
