{% extends 'base.html' %}

{% block title %}{{ _('Donations') }} - MetaBrainz Foundation{% endblock %}

{% block content %}
  <h1 class="page-title">{{ _('Donors') }}</h1>

  <p>
    <ul class="nav nav-pills">
      <li role="presentation" {{ 'class=active' if order == 'date' }}>
        <a href="{{ url_for('payments.donors', order='date') }}">{{ _('by date') }}</a>
      </li>
      <li role="presentation" {{ 'class=active' if order == 'amount' }}>
        <a href="{{ url_for('payments.donors', order='amount') }}">{{ _('by amount') }}</a>
      </li>
    </ul>
  </p>

  {% if not donations %}
    {{ _('No donations. :(') }}
  {% else %}
    <table class="table table-hover">
      <thead>
      <tr>
        <th>{{ _('Date') }}</th>
        <th>{{ _('Donor') }}</th>
        <th>{{ _('Donation') }}</th>
        <th>{{ _('Fee') }}</th>
      </tr>
      </thead>
      <tbody>
      {% for donation in donations %}
        <tr>
          <td>{{ donation.payment_date|datetime }}</td>
          <td>
            {% if donation.anonymous %}
              (anonymous)
            {% else %}
              {{ donation.first_name }} {{ donation.last_name }}
              {% if donation.editor_name %}
                (<a href="{{ config.MUSICBRAINZ_BASE_URL }}user/{{ donation.editor_name }}">{{ donation.editor_name }}</a>)
              {% endif %}
            {% endif %}
          </td>
          <td>{{ donation.amount|string + ' ' + donation.currency|upper }}</td>
          <td>{{ donation.fee|string + ' ' + donation.currency|upper if donation.fee else '-' }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>

    {% if (page - 4) > 0 %}
      {% set start = page - 4 %}
    {% else %}
      {% set start = 1 %}
    {% endif %}
    <nav>
      <ul class="pagination">
        <li {{ 'class=disabled' if page == 1 }}>
          <a href="{{ url_for('payments.donors', order=order, page=1) if page != 1 else '#' }}">
            <span aria-hidden="true">&laquo;</span><span class="sr-only">{{ _('First') }}</span>
          </a>
        </li>
        <li {{ 'class=disabled' if page == 1 }}>
          <a href="{{ url_for('payments.donors', order=order, page=page-1) if page != 1 else '#' }}">
            <span aria-hidden="true">&lsaquo;</span><span class="sr-only">{{ _('Previous') }}</span>
          </a>
        </li>

        {% for cur_page in range(start, last_page+1) %}
          {% if loop.index < 9 %}
            <li {{ 'class=active' if cur_page == page }}>
              <a href="{{ url_for('payments.donors', order=order, page=cur_page) }}">{{ cur_page }}</a>
            </li>
          {% endif %}
        {% endfor %}

        <li {{ 'class=disabled' if page == last_page }}>
          <a href="{{ url_for('payments.donors', order=order, page=page+1) if page != last_page else '#' }}">
            <span aria-hidden="true">&rsaquo;</span><span class="sr-only">Next</span>
          </a>
        </li>
        <li {{ 'class=disabled' if page == last_page }}>
          <a href="{{ url_for('payments.donors', order=order, page=last_page) if page != last_page else '#' }}">
            <span aria-hidden="true">&raquo;</span><span class="sr-only">Last</span>
          </a>
        </li>
      </ul>
    </nav>
  {% endif %}
{% endblock %}
