{% extends "base.html" %}
{% block content %}
<div class="level">
    <div class="level-left"><h1 class="title is-3">Benutzer bearbeiten: {{ user.full_name }}</h1></div>
    <div class="level-right">
        {% if current_user.is_superadmin() %}
        <a class="button is-small" href="{{ url_for('superadmin.firma_detail', company_id=user.company_id) }}">← Firma</a>
        {% else %}
        <a class="button is-small" href="{{ url_for('admin.firma') }}">← Firma</a>
        {% endif %}
    </div>
</div>

<div class="box">
    <form method="POST">
        <div class="columns is-multiline">
            <div class="column is-4">
                <div class="field">
                    <label class="label">E-Mail</label>
                    <div class="control">
                        <input class="input" type="email" name="email" value="{{ user.email }}" required>
                    </div>
                </div>
            </div>
            <div class="column is-3">
                <div class="field">
                    <label class="label">Vorname</label>
                    <div class="control">
                        <input class="input" type="text" name="vorname" value="{{ user.vorname or '' }}">
                    </div>
                </div>
            </div>
            <div class="column is-3">
                <div class="field">
                    <label class="label">Nachname</label>
                    <div class="control">
                        <input class="input" type="text" name="nachname" value="{{ user.nachname or '' }}">
                    </div>
                </div>
            </div>
            <div class="column is-2">
                <div class="field">
                    <label class="label">Rolle</label>
                    <div class="control">
                        <div class="select is-fullwidth">
                            <select name="rolle">
                                <option value="mitarbeiter" {{ 'selected' if user.rolle == 'mitarbeiter' }}>Mitarbeiter</option>
                                <option value="firmadmin" {{ 'selected' if user.rolle == 'firmadmin' }}>Firmadmin</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="column is-4">
                <div class="field">
                    <label class="label">Neues Passwort (leer lassen für keine Änderung)</label>
                    <div class="control">
                        <input class="input" type="password" name="password" minlength="6" placeholder="mind. 6 Zeichen">
                    </div>
                </div>
            </div>
            <div class="column is-8">
                <div class="field">
                    <label class="label">Berechtigungen</label>
                    <div class="control">
                        <label class="checkbox is-size-7 mr-3"><input type="checkbox" name="darf_projekte_anlegen" value="1" {{ 'checked' if user.darf_projekte_anlegen }}> Projekte anlegen</label>
                        <label class="checkbox is-size-7 mr-3"><input type="checkbox" name="darf_lv_verwalten" value="1" {{ 'checked' if user.darf_lv_verwalten }}> LV verwalten</label>
                        <label class="checkbox is-size-7 mr-3"><input type="checkbox" name="darf_preise_sehen" value="1" {{ 'checked' if user.darf_preise_sehen }}> Preise sehen</label>
                        <label class="checkbox is-size-7"><input type="checkbox" name="darf_aufmass_verwalten" value="1" {{ 'checked' if user.darf_aufmass_verwalten }}> Aufmaße verwalten</label>
                        {% if company and company.evergabe_aktiviert %}
                        <br>
                        <label class="checkbox is-size-7 mr-3"><input type="checkbox" name="darf_evergabe_nutzen" value="1" {{ 'checked' if user.darf_evergabe_nutzen }}> E-Vergabe Addon nutzen</label>
                        <label class="checkbox is-size-7 mr-3"><input type="checkbox" name="darf_kopfdaten_holen" value="1" {{ 'checked' if user.darf_kopfdaten_holen }}> Kopfdaten holen</label>
                        <label class="checkbox is-size-7"><input type="checkbox" name="darf_aufmass_uebertragen" value="1" {{ 'checked' if user.darf_aufmass_uebertragen }}> Aufmaße übertragen</label>
                        {% endif %}
                    </div>
                </div>
            </div>
            <div class="column is-12">
                <button class="button is-primary" type="submit">Speichern</button>
                {% if current_user.is_superadmin() %}
                <a class="button is-light" href="{{ url_for('superadmin.firma_detail', company_id=user.company_id) }}">Abbrechen</a>
                {% else %}
                <a class="button is-light" href="{{ url_for('admin.firma') }}">Abbrechen</a>
                {% endif %}
            </div>
        </div>
    </form>
</div>
{% endblock %}