{%- extends "manhattan/manage/generics/view.html" -%}
{%- import "manhattan/manage/components/status.html" as _status -%}
{%- import "manhattan/manage/components/sessions.html" as _sessions with context -%}

{% block main -%}

    {% set user = get_context()[manage_config.var_name] %}
    {% set locked_out = user.is_locked_out(user.email) %}

    {% call _boxes.box() -%}
        {% call _dataset.set() -%}

            {% call _dataset.head() -%}
                {% call _dataset.heading() -%}
                    Details

                    {% if user.invite_accepted %}
                        {{ _status.tag(
                            'Invite accepted',
                            class='mh-tag--invite-accepted'
                        ) }}
                    {% elif user.invited %}
                        {{ _status.tag(
                            'Invite pending',
                            class='mh-tag--invited'
                        ) }}
                    {% else %}
                        {{ _status.tag(
                            'Not yet invited',
                            class='mh-tag--not-invited'
                        ) }}
                    {% endif %}

                    {% if user.mfa_enabled %}
                        {{ _status.tag(
                            '2FA enabled',
                            class='mh-tag--mfa-enabled'
                        ) }}
                    {% endif %}

                    {% if locked_out %}
                        {{ _status.tag(
                            'Locked out',
                            class='mh-tag--locked-out'
                        ) }}
                    {% endif %}

                {%- endcall %}
            {%- endcall %}

            {% call _dataset.row() -%}
                {{ _dataset.column(
                    'Email',
                    user.email,
                    url='mailto:' + user.email
                    ) }}
                {% set last_accessed = user.last_accessed %}
                {{ _dataset.column(
                    'Last accessed',
                    last_accessed|humanize_datetime if last_accessed else 'Never'
                    ) }}
            {%- endcall %}

        {%- endcall %}
    {%- endcall %}

    {% if user_sessions %}
        {% call _boxes.box() -%}
            {% call _dataset.set('Sessions') -%}
                {{ _sessions.sessions(
                    user_sessions,
                    'manage_users.revoke_session',
                    user.current_session
                ) }}
            {% endcall %}
        {% endcall %}
    {% endif %}

    {% if not user.invite_accepted %}
        <form
            id="resend-invite-form"
            method="post"
            action="{{ url_for('manage_users.resend_invite') }}"
            >
            <input name="csrf_token" type="hidden" value="{{ csrf_token() }}">
            <input type="hidden" name="user" value="{{ user._id }}">
        </form>
    {% endif %}

    {% if locked_out %}
        <form
            id="remove-lock-form"
            method="post"
            action="{{ url_for('manage_users.remove_lock') }}"
            >
            <input name="csrf_token" type="hidden" value="{{ csrf_token() }}">
            <input type="hidden" name="user" value="{{ user._id }}">
        </form>
    {% endif %}

{%- endblock %}
