import { useState, type FormEvent } from "react"; import { api } from "@/api"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { t } from "@/i18n"; /** Login/setup gate shown when auth is enabled and no session exists. */ export function LoginPage({ setup, onDone }: { setup: boolean; onDone: () => void }) { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [err, setErr] = useState(""); const [busy, setBusy] = useState(false); async function submit(e: FormEvent) { e.preventDefault(); setErr(""); setBusy(true); const body = { username: username.trim(), password }; const { error, response } = setup ? await api.POST("/api/auth/setup", { body }) : await api.POST("/api/auth/login", { body }); setBusy(false); if (error) { setErr(response.status === 429 ? t("auth.rateLimited") : t("auth.invalid")); return; } onDone(); } return (