import { html } from 'lit'; import { LightElement } from '../lib/base.js'; import { t, I18nMixin } from '../lib/i18n.js'; export class LoginPage extends I18nMixin(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 = t('login.missing'); 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 = t('login.error'); return; } // Logged in — reload into the app. window.location.reload(); } catch { this._error = t('login.network'); } finally { this._busy = false; } } render() { const btnLabel = this._busy ? html`${t('login.signing')}` : t('login.submit'); return html`