{% extends "base.html" %}
{% import "macros.html" as macros %}

{% macro request_header(attr, title, class=None) -%}
<th id="col-{{ attr }}"{{ (' class="' ~ class ~ '"')|safe if class }}><a href="#" class="heading">{{ title }} 
{% if attr != None and attr in filters.get('sort', 'submit_timestamp') %}
{% if filters.get('sort', 'submit_timestamp')[0] == '-' %}
<i class="fa fa-chevron-up"></i>
{% else %}
<i class="fa fa-chevron-down"></i>
{% endif %}
{% else %}
<i></i>
{% endif %}
</a></th>
{%- endmacro %}

{% macro request_cell(attr, content, filterable=True) -%}
{% if (filterable == None and attr not in ['id', 'submit_timestamp', 'payout']) or filterable == True %}
<td class="filterable" data-attribute="{{ attr }}"><a href="#">{{ content }}</a></td>
{% else %}
<td data-attribute="{{ attr }}">{{ content }}</td>
{% endif %}
{%- endmacro %}

{% block head %}
{{ super() }}
<link rel="alternate" type="application/rss+xml" href="{{ url_for(request.endpoint, division_id=request.view_args.get('division_id'), _external=True) ~ 'rss.xml' }}">
{% endblock head %}

{% block content %}
<div class="row">
  <div id="request-list" class="col-md-10 col-md-offset-1">
    <div class="input-group form-group">
      {# TRANS: This is a label for a text box that allow people to search for requests meeting certain criteria, like what system the loss occured in, what ship type it was, who the pilot was, or what corporation they're in. #}
      <span class="input-group-addon">{% trans %}Filters{% endtrans %}</span>
      <input type="text" class="form-control filter-tokenfield">
    </div>
    {% block table %}
    <table class="table table-condensed" id="requests">
      <tr>
        {% block table_headers %}
        {# TRANS: A table column header for the ID number of a request. #}
        {{ request_header("id", gettext("Request ID")) }}
        {# TRANS: A table column header for the pilot of a request. #}
        {{ request_header("pilot", gettext("Pilot")) }}
        {# TRANS: A table column header for the ship from a request. #}
        {{ request_header("ship", gettext("Ship")) }}
        {# TRANS: A table column header for the pilot of a request. #}
        {{ request_header("system", gettext("System")) }}
        {# TRANS: A table column header for the status of a request (like evaluating, incomplete, approved, rejected). #}
        {{ request_header("status", gettext("Status")) }}
        {# TRANS: A table column header for the current payout of a request. #}
        {{ request_header("payout", gettext("Payout")) }}
        {# TRANS: A table column header for the date and time a request was submitted. #}
        {{ request_header("submit_timestamp", gettext("Submit Time")) }}
        {# TRANS: A table column header for the of the division a request was submitted to. #}
        {{ request_header("division", gettext("Division")) }}
        {% endblock table_headers %}
      </tr>
      {% for request in pager.items %}
      <tr class="{{ macros.status_color(request.status) }}">
        {% block table_row scoped %}
        <td data-attribute="id"><a href="{{ url_for('requests.get_request_details', request_id=request.id) }}">{{ request.id }}</a></td>
        {{ request_cell('pilot', request.pilot.name) }}
        {{ request_cell('ship', request.ship_type) }}
        {{ request_cell('system', request.system) }}
        {{ request_cell('status', request.status) }}
        {{ request_cell('payout', request.payout|currencyfmt, False) }}
        {{ request_cell('submit_timestamp', request.timestamp|datetimeformat(format='short'), False) }}
        {{ request_cell('division', request.division.name) }}
        {% endblock table_row %}
      </tr>
      {% endfor %}
    </table>
    {% endblock table %}
    {% block pagination %}
    <div class="text-center">
      {% if pager.pages > 1 %}
      <ul class="pagination">
      {% else %}
      <ul class="pagination hidden">
      {% endif %}
        {% if pager.has_prev %}
        <li><a id="prev_page" href="{{ url_for_page(pager, pager.prev_num) }}">&laquo;</a></li>
        {% else %}
        <li class="disabled"><span>&laquo;</span></li>
        {% endif %}
        {% for page in pager.iter_pages() %}
          {% if page %}
            {% if page != pager.page %}
        <li><a href="{{ url_for_page(request.endpoint, page) }}">{{ page }}</a></li>
            {% else %}
        <li class="active"><a href="{{ url_for_page(pager, page) }}">{{ page }}<span class="sr-only"> (current)</span></a></li>
            {% endif %}
          {% else %}
        <li class="disabled"><span>&hellip;</span></li>
          {% endif %}
        {% endfor %}
        {% if pager.has_next %}
        <li><a id="next_page" href="{{ url_for_page(pager, pager.next_num) }}">&raquo;</a></li>
        {% else %}
        <li class="disabled"><span>&raquo;</span></li>
        {% endif %}
      </ul>
      <p class="text-muted" id="requestsSummary">
      {# TRANS: A small line showing how many total requests there are. #}
      {{ ngettext('%(num)s request', '%(num)s requests', pager.total)|format(num=(pager.total|numberfmt)) }} &bull; {{ total_payouts|currencyfmt }} ISK
      </p>
    </div>
    {% endblock pagination %}
  </div>
</div>
{% endblock content %}
