{% extends 'base.jinja2' %}
{% import 'macros/form_macros.jinja2' as mform %}
{% block content %}
    <div class="col-12 ">
        <div class="row justify-content-center justify-content-sm-center">

            {% if not form %}
                <div class="col-12 col-sm-8 col-md-7 col-lg-5 col-xl-4 bg-white text-dark p-3 mt-5">
                    <div class="card">
                        <div class="card-body">
                            {% if user.deleted_user.deletion_date %}
                                <h5 class="card-title text-danger">{{ user.user.username }}
                                    <small>Als gelöscht markiert</small>
                                </h5>
                            {% else %}
                                <h5 class="card-title">{{ user.user.username }}</h5>
                            {% endif %}
                            <h6 class="card-subtitle mb-2 text-muted">{{ user.user.last_name }}, {{ user.user.first_name }}</h6>
                            <ul class="list-group list-group-flush">
                                {% if groups %}
                                    <li class="list-group-item">
                                        <span class="font-weight-bold">Gruppen:</span>
                                        {% for group in groups %}
                                            <span class="badge badge-primary p-1" data-toggle="tooltip"
                                                  data-placement="right"
                                                  title="{{ group.description }}"
                                            >{{ group.name }}</span>
                                        {% endfor %}
                                    </li>
                                {% endif %}
                                <li class="list-group-item"><span
                                        class="font-weight-bold">Email:</span> {{ user.user.email }}</li>
                                <li class="list-group-item"><span
                                        class="font-weight-bold">Passwort:</span> <a
                                        href="{{ url('password_change_controller') }}">Passwort ändern</a>
                                </li>
                                <li class="list-group-item"><span
                                        class="font-weight-bold">Telefon:</span> {{ user.user.phone }}</li>
                                <li class="list-group-item"><span
                                        class="font-weight-bold">Mobiltelefon:</span> {{ user.user.mobile_phone }}</li>
                                {% if user.deleted_user.deletion_date %}
                                    <li class="list-group-item text-danger">
                                        Löschvorgang: {{ user.deleted_user.deletion_date.strftime('%d.%m.%Y') }}
                                    </li>
                                {% endif %}
                            </ul>
                            <div class="card-footer d-flex bg-white">
                                <a href="{{ url('user-update', args = [realm.id, user.user.dn]) }}"
                                   class="btn btn-primary mr-auto p-2"><i class="fas fa-user-edit"></i> Profil
                                    bearbeiten</a>
                                <a href="{{ url('user-delete-confirm', args = [realm.id, user.user.dn]) }}"
                                   class="btn btn-danger p-2"><i class="fas fa-trash"></i> Profil löschen</a>
                            </div>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="col-12 col-sm-8 col-md-7 col-lg-5 col-xl-4 bg-white text-dark p-3 mt-5 border">
                    <h1 class="mb-4">Nutzerdetails anpassen</h1>
                    <form method="post" class="floating-label-form" enctype="multipart/form-data">
                        <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
                        {{ mform.email_input(form.email) }}
                        {{ mform.text_input(form.first_name) }}
                        {{ mform.text_input(form.last_name) }}
                        {{ mform.text_input(form.phone) }}
                        {{ mform.text_input(form.mobile_phone) }}
                        <div class="d-flex mt-4">
                            <button type="submit" class="btn btn-primary mr-auto p-2">Speichern</button>
                            <a href="{{ url('user-detail', args = [realm.id, user.dn]) }}"
                               class="btn btn-secondary p-2">Abbrechen</a>
                        </div>
                    </form>
                </div>
            {% endif %}
        </div>
    </div>
    </div>
{% endblock %}
