import { html } from 'lit'; import { LightElement } from '../lib/base.js'; export class LoginPage extends LightElement { static get properties() { return { _username: { state: true }, _password: { state: true }, _error: { state: true }, _busy: { state: true }, }; } constructor() { super(); this._username = ''; this._password = ''; this._error = null; this._busy = false; } _submit(e) { e.preventDefault(); if (this._busy) return; this._error = null; if (!this._username.trim() || !this._password) { this._error = 'Enter your username and password.'; return; } this._doLogin(); } async _doLogin() { this._busy = true; try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: this._username.trim(), password: this._password, }), }); if (!res.ok) { this._error = 'Invalid username or password.'; return; } // Logged in — reload into the app. window.location.reload(); } catch { this._error = 'Network error — please try again.'; } finally { this._busy = false; } } render() { const btnLabel = this._busy ? html`Signing in…` : 'Sign in'; return html`