{% extends "_layout.html" %}

{% block content %}

                <div>
                    {{ macros_page.render_breadcrumbs(item) }}

                    <h3>{{ item.fullname }} ({{ item.login }})</h3>
                    <div class="float-end">
                        {{ macros_page.render_menu_actions(item) }}

                    </div>
                    <p>
                        <small>
                            <strong>{{ _('Account created') }}:</strong> {{ babel_format_datetime(item.createtime) }} ({{ _('%(delta)s ago', delta = babel_format_timedelta(current_datetime_utc - item.createtime)) }})
                            &nbsp;|&nbsp;
                            <strong>{{ _('Last login') }}:</strong> {% if item.logintime %}{{ babel_format_datetime(item.logintime) }} ({{ _('%(delta)s ago', delta = babel_format_timedelta(current_datetime_utc - item.logintime)) }}){% else %}{{ _('never') }}{% endif %}
                        </small>
                    </p>
                    <br>

                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="nav-item">
                            <a href="#tab-general" aria-controls="tab-general" role="tab" data-bs-toggle="tab" class="nav-link active">
                                <strong>{{ get_icon('alert-info') }} {{ _('General information') }}</strong>
                            </a>
                        </li>
                        {%- if can_access_endpoint('users.update', item) %}
                        <li role="presentation" class="nav-item">
                            <a href="#tab-actionlog" aria-controls="tab-actionlog" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('module-changelogs') }} {{ _('Actionlogs') }}</strong> <span class="badge rounded-pill  text-bg-secondary">{{ user_changelog | length }}</span>
                            </a>
                        </li>
                        {%- endif %}
                        {%- if can_access_endpoint('users.update', item) %}
                        <li role="presentation" class="nav-item">
                            <a href="#tab-changelog" aria-controls="tab-changelog" role="tab" data-bs-toggle="tab" class="nav-link">
                                <strong>{{ get_icon('module-changelogs') }} {{ _('Changelogs') }}</strong> <span class="badge rounded-pill  text-bg-secondary">{{ item_changelog | length }}</span>
                            </a>
                        </li>
                        {%- endif %}
                    </ul>

                    <!-- Tab panes -->
                    <div class="tab-content">

                        <div role="tabpanel" class="tab-pane fade in show active" id="tab-general">
                            <br>
                            <div class="row">

                                <div class="col-md-4">
                                    <h5>{{ _('Metadata') }}</h5>
                                    <table class="table table-striped">
                                        <tbody>
                                            <tr>
                                                <th>
                                                    {{ _('Login') }}:
                                                </th>
                                                <td>
                                                    {{ item.login | default(_('<< unknown >>'), True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Full name') }}:
                                                </th>
                                                <td>
                                                    {{ item.fullname | default(_('<< unknown >>'), True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('E-mail') }}:
                                                </th>
                                                <td>
                                                    {%- if item.email %}
                                                    <a href="mailto:{{ item.email }}">{{ item.email }}</a>
                                                    {%- else %}
                                                    {{ _('<< unknown >>') }}
                                                    {%- endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Home organization') }}:
                                                </th>
                                                <td>
                                                    {{ item.organization | default(_('<< unknown >>'), True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('State') }}:
                                                </th>
                                                <td>
                                                    {{ macros_site.render_label_item_state(item.enabled, True) }}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Roles') }}:
                                                </th>
                                                <td>
                                                    {{ macros_site.render_labels_role_list(config['ROLES'], item, True) }}
                                                </td>
                                            </tr>
                                            {%- if can_access_endpoint('auth_api.key-generate', item) or item.apikey %}
                                            <tr>
                                                <th>
                                                    {{ _('API access key') }}:
                                                </th>
                                                <td>
                                                    {%- if item.apikey %}
                                                    <div class="input-group">
                                                        {%- if is_it_me(item) %}
                                                        <input type="text" value="{{ item.apikey }}" readonly="readonly" class="form-control">
                                                        {%- endif %}
                                                        <a role="button" class="btn {% if is_it_me(item) %}btn-outline-tertiary{% else %}btn-outline-dark{% endif %}" href="{{ url_for('auth_api.key-delete', item_id = item.id, next = request.url) }}" data-bs-toggle="tooltip" title="{{ get_endpoint_class('auth_api.key-delete').get_menu_legend() }}">
                                                            {{ get_icon(get_endpoint_class('auth_api.key-delete').get_view_icon()) }}{% if not is_it_me(item) %} {{ get_endpoint_class('auth_api.key-delete').get_menu_title() }}{% endif %}
                                                        </a>
                                                    </div>
                                                    {%- else %}
                                                    <div class="input-group">
                                                        <span class="input-group-btn">
                                                            <a role="button" class="btn btn-outline-dark btn-sm" href="{{ url_for('auth_api.key-generate', item_id = item.id, next = request.url) }}" data-bs-toggle="tooltip" title="{{ get_endpoint_class('auth_api.key-generate').get_menu_legend() }}">
                                                                {{ get_icon(get_endpoint_class('auth_api.key-generate').get_view_icon()) }} {{ get_endpoint_class('auth_api.key-generate').get_menu_title() }}
                                                            </a>
                                                        </span>
                                                    </div>
                                                    {%- endif %}
                                                </td>
                                            </tr>
                                            {%- endif %}
                                            <tr>
                                                <th>
                                                    {{ _('Preferred locale') }}:
                                                </th>
                                                <td>
                                                    {%- if item.locale %}
                                                    {{ get_country_flag(item.locale|upper) }} {{ babel_translate_locale(item.locale, True) }} ({{ item.locale }})
                                                    {%- else %}
                                                    {{ _('<< system default >>') }}
                                                    {%- endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>
                                                    {{ _('Preferred timezone') }}:
                                                </th>
                                                <td>
                                                    {%- if item.timezone %}
                                                    {{ item.timezone }}
                                                    {%- else %}
                                                    {{ _('<< system default >>') }}
                                                    {%- endif %}
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>

                                <div class="col-md-4">
                                    {%- if item.memberships_wanted %}
                                    <h5>
                                        {{ _('Group membership requests') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.memberships_wanted | length }}</span>
                                    </h5>
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.memberships_wanted %}
                                            <tr>
                                                <td>
                                                    {{ subitem.name }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_groups, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- endif %}
                                    <h5>
                                        {{ _('Group memberships') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.memberships | length }}</span>
                                    </h5>
                                    {%- if item.memberships %}
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.memberships %}
                                            <tr>
                                                <td>
                                                    {{ subitem.name }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_groups, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- else %}
                                    {%- call macros_site.render_alert('info', False) %}
                                    {{ _('This user is not member of any group at the moment.') }}
                                    {%- endcall %}
                                    {%- endif %}
                                </div>

                                <div class="col-md-4">
                                    <h5>{{ _('Group managements') }} <span class="badge rounded-pill text-bg-secondary my-n2">{{ item.managements | length }}</span></h5>
                                    {%- if item.managements %}
                                    <table class="table table-striped">
                                        <tbody>
                                            {%- for subitem in item.managements %}
                                            <tr>
                                                <td>
                                                    {{ subitem.name }}
                                                </td>
                                                <td>
                                                    {{ macros_page.render_menu_context_actions(subitem, context_action_menu_groups, kwargs = {'other': item}) }}
                                                </td>
                                            </tr>
                                            {%- endfor %}
                                        </tbody>
                                    </table>
                                    {%- else %}
                                    {%- call macros_site.render_alert('info', False) %}
                                    {{ _('This user is not manager of any group at the moment.') }}
                                    {%- endcall %}
                                    {%- endif %}
                                </div>

                            </div>
                        </div>

                        {%- if can_access_endpoint('users.update', item) %}
                        <div role="tabpanel" class="tab-pane fade" id="tab-actionlog">
                            <br>
                            {%- if user_changelog %}
                            {{ macros_page.render_changelog_records(user_changelog, context_action_menu_changelogs, idprefix = 'actionlog', hide_author = True) }}
                            <p>
                                <small>
                                    {{ _('Displaying only latest %(count)s actionlogs', count = 100) }}
                                </small>
                            </p>
                            {%- else %}
                            {%- call macros_site.render_alert('info', False) %}
                            {{ _('This user does not have any actionlog records at the moment.') }}
                            {%- endcall %}
                            {%- endif %}
                        </div>
                        {%- endif %}

                        {%- if can_access_endpoint('users.update', item) %}
                        <div role="tabpanel" class="tab-pane fade" id="tab-changelog">
                            <br>
                            {%- if item_changelog %}
                            {{ macros_page.render_changelog_records(item_changelog, context_action_menu_changelogs, hide_item = True) }}
                            <p>
                                <small>
                                    {{ _('Displaying only latest %(count)s changelogs', count = 100) }}
                                </small>
                            </p>
                            {%- else %}
                            {%- call macros_site.render_alert('info', False) %}
                            {{ _('This object does not have any changelog records at the moment.') }}
                            {%- endcall %}
                            {%- endif %}
                        </div>
                        {%- endif %}

                    </div>

                </div>

    {%- if permission_can('developer') %}

            <hr>

            {{ macros_site.render_raw_item_view(item) }}

    {%- endif %}

{% endblock content %}
