{% extends "cranefly/layout.html" %}
{% import "_forms.html" as form_theme with context %}
{% import "cranefly/macros.html" as macros with context %}

{% block title %}{% if in_search -%}
{{ macros.page_title(title=_('Search Users'), parent=_('Users List')) }}
{% elif active_rank %}
{{ macros.page_title(title=_(active_rank.name), parent=_('Users List')) }}
{%- else -%}
{{ macros.page_title(title=_('Users List')) }}
{%- endif %}{% endblock %}

{% block container %}
<div class="page-header header-primary">
  <div class="container">
    {{ messages_list(messages) }}
    <h1>{% trans %}Users List{% endtrans %} <small>{% trans %}Browse notable user groups or find specific user{% endtrans %}</small></h1>
    <ul class="nav nav-tabs header-tabs">
      {% for rank in ranks %}
      <li{% if active_rank.id == rank.id %} class="active"{% endif %}><a href="{% if loop.first %}{% url 'users' %}{% else %}{% url 'users' slug=rank.slug %}{% endif %}">{{ _(rank.name) }}</a></li>
      {% endfor %}
      {% if acl.users.can_search_users() and not user.is_crawler() %}
      <li class="pull-right">
        <form action="{% url 'users' %}" class="form-inline" method="post">
          <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
          {{ form_theme.field_widget(search_form.username, width=2, attrs={'placeholder': lang_find_user()}) }}
          <button type="submit" class="btn btn-icon"><i class="icon-search"></i></button>
        </form>
      </li>
      {% endif %}
    </ul>
  </div>
</div>

<div class="container container-primary">
  <div class="profiles-list">

    {% if in_search %}<h2>{% trans %}Search Users{% endtrans %}</h2>{% endif %}

    {% if message %}
    <div class="messages-list">
      {{ macros.draw_message(message, 'alert-form') }}
    </div>
    {% endif %}

    {% if in_search and not message and users|length > 0 %}
    <p class="lead">{% trans %}We couldn't find a member with name you entered, so we present you with some other members with names similiar to one you searched for in hopes that one of them will turn out to be member you are looking for.{% endtrans %}</p>
    {% elif active_rank and active_rank.description %}
    <div class="markdown lead">{{ active_rank.description }}</div>
    {% endif %}

    {% if users|length > 0 %}
    <table class="table table-striped">
      <thead>
        <tr>
          <th colspan="4">{% if in_search %}{% trans %}Found Users{% endtrans %}{% else %}{% trans %}Users in this group{% endtrans %}{% endif %}</th>
        </tr>
      </thead>
      <tbody>
        {% for row in users|batch(4, '') %}
        <tr>
          {% for user in row %}
          <td class="span3 user-cell{% if user and user.get_style() %} user-cell-{{ user.get_style() }}{% endif %}">
            {% if user %}
            <a href="{% url 'user' username=user.username_slug, user=user.pk %}" class="user-avatar"><img src="{{ user.get_avatar(36) }}" alt=""></a>
            <a href="{% url 'user' username=user.username_slug, user=user.pk %}" class="user-name">{{ user.username }}</a>
            {% else %}
            &nbsp;
            {% endif %}
          </td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {{ pager() }}
    {% elif not message %}
    <p class="lead">
      {%- if in_search -%}
      {% trans %}We couldn't find any members with specified name.{% endtrans %}
      {%- else -%}
      {% trans %}Looks like this group has no members...{% endtrans %}
      {%- endif -%}
    </p>
    {% endif %}

  </div>
</div>
{% endblock %}

{% macro pager() -%}
{% if pagination and pagination['total'] > 1 %}
{% if default_rank %}
<div class="pagination">
  <ul>
    <li class="count">{{ macros.pager_label(pagination) }}</li>
    {%- if pagination['prev'] > 0 %}<li><a href="{%- if pagination['prev'] > 1 %}{% url 'users' page=pagination['prev'] %}{% else %}{% url 'users' %}{% endif %}" class="tooltip-top" title="{% trans %}Previous Page{% endtrans %}"><i class="icon-chevron-left"></i></a></li>{% endif -%}
    {%- if pagination['next'] > 0 %}<li><a href="{% url 'users' page=pagination['next'] %}" class="tooltip-top" title="{% trans %}Next Page{% endtrans %}"><i class="icon-chevron-right"></i></a></li>{% endif -%}
  </ul>
</div>
{% else %}
<div class="pagination">
  <ul>
    <li class="count">{{ macros.pager_label(pagination) }}</li>
    {%- if pagination['prev'] > 0 %}<li><a href="{%- if pagination['prev'] > 1 %}{% url 'users' slug=active_rank.slug, page=pagination['prev'] %}{% else %}{% url 'users' slug=active_rank.slug %}{% endif %}" class="tooltip-top" title="{% trans %}Previous Page{% endtrans %}"><i class="icon-chevron-left"></i></a></li>{% endif -%}
    {%- if pagination['next'] > 0 %}<li><a href="{% url 'users' slug=active_rank.slug, page=pagination['next'] %}" class="tooltip-top" title="{% trans %}Next Page{% endtrans %}"><i class="icon-chevron-right"></i></a></li>{% endif -%}
  </ul>
</div>
{% endif %}
{% endif %}
{%- endmacro %}

{# Language strings macros #}
{% macro lang_find_user() -%}{% trans %}Find User...{% endtrans %}{%- endmacro %}