{% import "macro/table.html" as table %}
<table class="ui attached table users">
    <thead>
        <tr>
            {% if user.can_read("jpegPhoto") %}
                <th></th>
            {% endif %}
            {% if user.can_read("uid") %}
                <th>{% trans %}Login{% endtrans %}</th>
            {% endif %}
            {% if user.can_read("sn") or user.can_read("givenName") %}
                <th>{% trans %}Name{% endtrans %}</th>
            {% endif %}
            {% if user.can_read("mail") %}
                <th>{% trans %}Email{% endtrans %}</th>
            {% endif %}
            {% if user.can_manage_groups %}
                <th>{% trans %}Groups{% endtrans %}</th>
            {% endif %}
        </tr>
    </thead>
    <tbody>
        {% for watched_user in table_form.items_slice %}
            <tr>
                {% if user.can_read("jpegPhoto") %}
                    <td>
                        <a href="{{ url_for('account.profile_edition', username=watched_user.uid[0]) }}">
                            {% if watched_user.jpegPhoto and watched_user.jpegPhoto[0] %}
                                <img class="ui avatar image" src="{{ url_for("account.photo", uid=watched_user.uid[0], field="jpegPhoto") }}" alt="User photo">
                            {% else %}
                                <i class="user circle big black icon"></i>
                            {% endif %}
                        </a>
                    </td>
                {% endif %}
                {% if user.can_read("uid") %}
                    <td><a href="{{ url_for('account.profile_edition', username=watched_user.uid[0]) }}">{{ watched_user.uid[0] }}</a></td>
                {% endif %}
                {% if user.can_read("sn") or user.can_read("givenName") %}
                    <td>{{ watched_user.name }}</td>
                {% endif %}
                {% if user.can_read("mail") %}
                    <td><a href="mailto:{{ watched_user.mail[0] }}">{{ watched_user.mail[0] }}</a></td>
                {% endif %}
                {% if user.can_manage_groups %}
                    <td>
                        {% for group in watched_user.groups %}
                            <a class="ui label" href="{{ url_for('groups.group', groupname=group.display_name) }}"{% if group.description %} title="{{ group.description[0] }}"{% endif %}>
                                {{ group.display_name }}
                            </a>
                        {% endfor %}
                    </td>
                {% endif %}
            </tr>
        {% else %}
            <tr>
                <td colspan="5">
                    <div class="ui icon message">
                        <i class="exclamation icon"></i>
                        <div class="content">
                            {% if request.headers.get("Hx-Request") %}
                                <div class="header">
                                    {% trans %}No item matches your request{% endtrans %}
                                </div>
                                <p>{% trans %}Maybe try with different criterias?{% endtrans %}</p>
                            {% else %}
                                <div class="header">
                                    {% trans %}There is nothing here{% endtrans %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </td>
            </tr>
        {% endfor %}
    </tbody>
    <tfoot>
        <tr>
            <th colspan="5">
                {{ table.pagination(table_form) }}
            </th>
        </tr>
    </tfoot>
</table>
