import { useState } from "preact/hooks"; import * as api from "../api/client.js"; import { session } from "../store/session.js"; import { Button } from "../ui/Button.jsx"; export function LoginGate() { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); async function onSubmit(e) { e.preventDefault(); if (busy) return; setBusy(true); setError(""); try { await api.login(username.trim(), password); const m = await api.me(); session.value = { ...session.value, ...m, authenticated: true, username: (m && m.username) || username.trim(), checked: true, }; } catch (err) { setError((err && err.message) || "Ошибка входа"); } finally { setBusy(false); } } return (