{% extends "base.html" %}

{% set active_page = "logged-in-user" %}

{% block title %} User {{ user.username }} {% endblock %}

{% block divs %}

<div class="container-fluid" style="text-align:center;">
    <a href="/users">Return to user overview</a>
</div>

{% if user %}

    <h2> Overview for user {{ user.username }} </h2>

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-1">
                <form action="/users/reset_password_for/{{ user.id }}" method="get">
                    <button class="btn btn-sm btn-responsive btn-info" type="submit"
                     title="Reset the password and send instructions how to choose a new one.">Reset password</button>
                </form>
            </div>
            <div class="col-sm-1">
                <form action="/users/toggle_active/{{ user.id }}" method="get">
                    <button class="btn btn-sm btn-responsive {% if user.active %} btn-warning  {% else %} btn-success {% endif %}" type="submit"
                     title="Toggle activation status of this user.">
                        {% if user.active %} Deactivate user {% else %} Activate user {% endif %}
                    </button>
                </form>
            </div>
            <div class="col-sm-10">
            </div>
        </div>

        <div class="row" style="margin-top: 1em;">
            <div class="col-sm-12">
                <table class="table">
                    <tbody>
                        <tr>
                            <td>
                                Email address
                            </td>
                            <td>
                                <a href="mailto:{{ user.email }}">{{ user.email }}</a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Time Zone
                            </td>
                            <td>
                                {{ user.timezone }}
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Account
                            </td>
                            <td>
                                {{ user.account.name }}
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Last login was
                            </td>
                            <td>
                                {{  user.last_login_at | localized_datetime }}
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Assets owned
                            </td>
                            <td>
                                <a href="/assets/owned_by/{{ user.id }}">{{ asset_count }}</a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Roles
                            </td>
                            <td>{% for role in user.flexmeasures_roles %}
                                  {{ role.name }}{{ "," if not loop.last }}
                                {% endfor %}
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Active
                            </td>
                            <td>
                                {{ user.active }}
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

{% endif %}

{% endblock %}