{% extends "base.html" %}
{% load i18n %}
{% load url_replace %}
{% load css_sort_class_select %}

{% block browser__menu %}cur{% endblock %}
{% block content %}
<table class="g g_middle g_max g_padding-b_XL">
  <tr>
    <td class="c">
      <div class="title">
        <h2>{% trans "Награды" %}</h2>
      </div>
    <td class="c c_right">
      <form method="GET" action="" class="browser_form_reward">
        <span class="radiogroup browser_form_reward_filter">
          {% for code, status_description in form.status.field.choices %}
          <button class="button button_size_M button_type_normal button_mode_radio {% if status == code %}button_state_check {% endif %}">
            <span class="button__label">{{ status_description }}</span>
            <input type="radio" name="status" value="{{ code }}" {% if status == code %}checked{% endif %}>
          </button>
          {% endfor %}
        </span>
      </form>
  </tr>
</table>

<table class="b-t">
    <thead>
        {% if messages %}
            <tr>
                {% for message in messages %}
                    <p class="{{ message.tags }}">{{ message }}</p>
                {% endfor %}
            </tr>
        {% endif %}
        <tr>
          <th class="th-sort {% css_sort_class_select 'id' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='id' reverse=reverse_id %}" class="link">{% trans "ID награды" %}</a>
              <i></i>
            </span>
          <th class="th-sort {% css_sort_class_select 'reporter' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='reporter' reverse=reverse_reporter %}" class="link">{% trans "Пользователь" %}</a>
              <i></i>
            </span>
          <th class="th-sort {% css_sort_class_select 'ticket_code' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='ticket_code' reverse=reverse_ticket_code %}" class="link">{% trans "OTRS-тикет" %}</a>
              <i></i>
            </span>
          <th class="th-sort {% css_sort_class_select 'ticket_created' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='ticket_created' reverse=reverse_ticket_created %}" class="link">{% trans "Время создания тикета OTRS" %}</a>
              <i></i>
            </span>
          <th class="th-sort {% css_sort_class_select 'payment_created' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='payment_created' reverse=reverse_payment_created %}" class="link">{% trans "Время создания награды" %}</a>
              <i></i>
            </span>
          <th class="b-t__right">
            <span>{% trans "Выплата" %}
              <i></i>
            </span>
          <th class="th-sort {% css_sort_class_select 'status' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='status' reverse=reverse_status %}" class="link">{% trans "Статус" %}</a>
              <i></i>
            </span>
          <th>
          <th class="th-sort {% css_sort_class_select 'balance_contract_created' 'sort-down' 'sort-up' %}">
            <span class="sort">
              <a href="?{% url_replace sort='balance_contract_created' reverse=reverse_balance_contract_created %}" class="link">{% trans "Выгрузка в YT" %}</a>
              <i></i>
            </span>
          </th>
        </tr>
    </thead>
    <tbody>
        {% for reward, reporter_login in rewards %}
        <tr {% if reward.status == 2 %}class="b-t__gray"{% endif %}>
            <td class="b-t__mw250"><a href="{% url 'reward-edit' reward_id=reward.id %}" class="link">{{ reward.id }}</a></td>
            <td><span class="user-login">
                {% if reward.reporter %}<a href="{% url 'user_profile:edit_payment' pk=reward.reporter.id %}">{%endif%}
                    {{ reporter_login }}
                {% if reward.reporter %}</a>{% endif %}
            </span></td>
            <td class="b-t__mw250"><a href="{{ reward.startrek_ticket_url }}" class="link">{{ reward.get_full_ticket_info }}</a></td>
            <td>{{ reward.ticket_created|date:"Y-m-d H:i:s" }}</td>
            <td>{{ reward.payment_created|date:"Y-m-d H:i:s" }}</td>
            <td class="b-t__right">{{ reward.humanized_payment }}</td>
            <td>{{ reward.get_status_display }}</td>
            <td class="b-t__ctrl">
                <a href="{% url 'reward-edit' reward_id=reward.id %}" class="button button_size_S button_type_clear button_icon-only_yes button_fontello button_hover">
                    <span class="icon-edit"></span>
                    <span class="button__label"></span>
                </a>
            </td>
            <td>{{ reward.balance_contract_created|date:"Y-m-d" }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

{% include "include/pagination.html" %}

{% endblock %}
