{% extends "base.html" %}
{% block title %}Benutzer{{ " - " + app_name() }}{% endblock %}

{% block content %}
<div class="page-header">
    <h1>Benutzer</h1>
    <a href="/einstellungen" role="button" class="btn-sm outline">Zurück</a>
</div>

<div class="card">
    <div class="card-header"><h3>Neuer Benutzer</h3></div>
    <form method="post" action="/einstellungen/benutzer/neu" style="display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap;">
        <div>
            <label for="kuerzel">Kürzel</label>
            <input type="text" id="kuerzel" name="kuerzel" required maxlength="10" style="margin: 0; width: 80px; text-transform: uppercase;">
        </div>
        <div>
            <label for="name">Name</label>
            <input type="text" id="name" name="name" required style="margin: 0;">
        </div>
        <div>
            <label for="passwort">Passwort</label>
            <input type="password" id="passwort" name="passwort" required style="margin: 0;">
        </div>
        <div>
            <label><input type="checkbox" name="ist_admin"> Admin</label>
        </div>
        <button type="submit" class="btn-sm" style="margin-bottom: 4px;">Anlegen</button>
    </form>
</div>

<div class="card">
    <div class="card-header"><h3>Benutzer ({{ benutzer|length }})</h3></div>
    <table class="data-table">
        <thead>
            <tr>
                <th>Kürzel</th>
                <th>Name</th>
                <th>E-Mail</th>
                <th>Admin</th>
                <th>Aktiv</th>
                <th>Letzter Login</th>
            </tr>
        </thead>
        <tbody>
            {% for b in benutzer %}
            <tr>
                <td><strong>{{ b.kuerzel }}</strong></td>
                <td>{{ b.name }}</td>
                <td>{{ b.email or '-' }}</td>
                <td>{% if b.ist_admin %}✅{% else %}-{% endif %}</td>
                <td>{% if b.ist_aktiv %}✅{% else %}❌{% endif %}</td>
                <td>{{ b.letzter_login.strftime('%d.%m.%Y %H:%M') if b.letzter_login else 'Noch nie' }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
