{% load i18n common_tags %}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{% blocktrans with object.display_name as user %}Report for {{ user }}, {% endblocktrans %}{% format_date_range start end " &ndash; " %} | {{ settings.POOTLE_TITLE }}</title>
  <base href="http://{{ request.META.HTTP_HOST }}" />
  <style type="text/css">
    html
    {
      font-family: sans-serif;
      font-size: 15px;
      background-color: #fff;
      color: #130f30;
    }

    table, caption, th, td
    {
      margin: 0;
    }

    table
    {
      border: 1px solid #e9e9e9;
      border-collapse: collapse;
      border-spacing: 0;
      padding: 0;
      width: 100%;
    }

    caption, th, td
    {
      border: 1px solid #d9d9d9;
      padding: 0.5em;
    }

    caption, th
    {
      line-height: 1em;
    }

    caption
    {
      background-color: #eee;
      border-style: solid solid none;
      font-size: 1.2em;
      font-weight: normal;
    }

    th
    {
      background-color: #f8f8f8;
      font-weight: 300;
      text-align: center;
    }

    tbody
    {
      line-height: 1.6;
    }

    td
    {
      vertical-align: top;
    }

    tr.empty td
    {
      text-align: center;
      font-style: italic;
    }

    .number
    {
      text-align: right;
    }

    .number sup
    {
      float:left;
      margin: -5px;
    }

    a
    {
      text-decoration: none;
    }

    .total td
    {
      font-weight: bold;
      vertical-align: baseline;
    }

    .total td.number
    {
      font-size: 130%;
    }

    .dates ul
    {
      font-size: 75%;
      padding: 0;
    }

    .dates li
    {
      display: inline-block;
      list-style: none;
    }

    .dates li.selected
    {
      font-size: 125%;
      font-weight: bold;
      width: 10em;
    }

    .dates .arrow
    {
      font-size: 130%;
    }
  </style>
</head>
<body>
  {% if object %}
  <table>
    <caption>
      <h2>{% blocktrans with object.display_name as user %}Report for {{ user }}{% endblocktrans %}</h2>
      <div class="dates">
        {% block dates %}
        <ul>
          <li class="previous"><a href="{% url 'pootle-reports-detailed' %}?username={{object.username}}&amp;month={{previous|date:'Y-m'}}"><span class="arrow">&larr;</span> {% trans "Previous month" %}</a></li>
          <li class="selected">{{start|date:'E, Y'}}</li>
          <li class="next"><a href="{% url 'pootle-reports-detailed' %}?username={{object.username}}&amp;month={{next|date:'Y-m'}}">{% trans "Next month" %} <span class="arrow">&rarr;</span></a></li>
        </ul>
        {% endblock dates %}
      </div>
    </caption>
    <thead>
      <tr>
        <th id="datetime">{% trans "Local server time" %} (GMT{{ utc_offset }})</th>
        <th id="action">{% trans "Action" %}</th>
        <th id="unit">{% trans "Unit" %}</th>
        <th id="source-words">{% trans "Source words" %}</th>
        <th id="similarity">{% trans "Similarity" %}</th>
        <th id="words">{% trans "Words" %}</th>
        {% if own_report and object.rate > 0 or admin_report and object.rate > 0 %}
          <th id="rate">{% trans "Rate" %}</th>
          <th id="subtotal">{% trans "Subtotal" %}</th>
        {% endif %}
      </tr>
    </thead>
    <tbody>
    {% for item in items %}
      {% if item.score %}
        {% with score=item.score %}
          <tr>
            <td>{{ item.creation_time }}</td>
            <td>{{ item.action_name }}</td>
            <td class="unit">
              {% if score.submission.unit.isobsolete %}
                <strike>#{{ score.submission.unit.id }}</strike>
              {% else %}
                <a href="{{ score.submission.unit.get_translate_url }}">#{{ score.submission.unit.id }}</a>
              {% endif %}
            </td>
            <td class="number">{{ item.wordcount }}</td>
            <td class="number">
              {% if score.is_similarity_taken_from_mt %}<sup>MT</sup>{% endif %}
              {% if item.action == action_types.REVIEW %}
                &mdash;
              {% elif item.action == action_types.TRANSLATION or item.action == action_types.SUGGESTION %}
                {% if item.similarity == 0 %}&lt; 50{% else %}{{ item.similarity|floatformat }}{% endif %}%
              {% endif %}
            </td>
            <td class="number">{{ item.wordcount|floatformat:2 }}</td>
            {% if object.rate > 0 and own_report or object.rate > 0 and admin_report %}
              <td class="number">
                {% if item.action != action_types.SUGGESTION %}
                  {% if item.action == action_types.REVIEW %}
                    {{ score.review_rate }}
                  {% elif item.action == action_types.TRANSLATION %}
                    {{ score.rate }}
                  {% endif %}
                    {{ object.currency }}
                {% else %}
                  &mdash;
                {% endif %}
              </td>
              <td class="number">
                {% if item.action != action_types.SUGGESTION %}
                  {{ item.subtotal|floatformat:4 }} {{ object.currency }}
                {% else %}
                  &mdash;
                {% endif %}
              </td>
            {% endif %}
          </tr>
        {% endwith %}
      {% else %}
        {% if own_report and object.rate > 0 or admin_report and object.rate > 0 %}
          {% with task=item.task %}
            <tr>
              <td>{{ task.datetime }}</td>
              <td colspan="4">{{ item.action_name }} ({% trans "registered tasks" %})</td>
              <td class="number">{{ task.amount }}</td>
              <td class="number">{{ task.rate }} {{ object.currency }}</td>
              <td class="number">{{ item.subtotal }} {{ object.currency }}</td>
            </tr>
          {% endwith %}
        {% endif %}
      {% endif %}

    {% empty %}
      <tr class="empty">
        <td colspan="8">{% trans "No activity recorded in a given period" %}</td>
      </tr>
    {% endfor %}
    {% if items %}
    <tr class="separator">
        <th colspan="8"></th>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td colspan="4">{% trans "Suggestion (subtotal)" %}</td>
      <td class="number">{% if totals.suggested > 0 %}{{ totals.suggested }}{% else %}&mdash;{% endif %}</td>
      {% if object.rate > 0 and own_report or object.rate > 0 and admin_report %}
        <td class="number">&mdash;</td>
        <td class="number">&mdash;</td>
      {% endif %}
    </tr>
    {% for rate, item in totals.translated.items %}
      <tr>
        <td>&nbsp;</td>
        <td colspan="4">{% trans "Translation (subtotal)" %}</td>
        <td class="number">{% if item.words > 0 %}{{ item.words }}{% else %}&mdash;{% endif %}</td>
        {% if object.rate > 0 and own_report or object.rate > 0 and admin_report %}
          <td class="number">{{ rate }} {{ object.currency }}</td>
          <td class="number">
            {% if item.subtotal > 0 %}
              {{ item.subtotal|floatformat:4 }} {{ object.currency }}
            {% else %}&mdash;{% endif %}
          </td>
        {% endif %}
      </tr>
    {% endfor %}
    {% for rate, item in totals.reviewed.items %}
      <tr>
        <td>&nbsp;</td>
        <td colspan="4">{% trans "Review (subtotal)" %}</td>
        <td class="number">{% if item.words > 0 %}{{ item.words }}{% else %}&mdash;{% endif %}</td>
        {% if object.rate > 0 and own_report or object.rate > 0 and admin_report %}
          <td class="number">{{ rate }} {{ object.currency }}</td>
          <td class="number">{% if item.subtotal > 0 %}{{ item.subtotal|floatformat:2 }} {{ object.currency }}{% else %}&mdash;{% endif %}</td>
        {% endif %}
      </tr>
    {% endfor %}
      {% if object.rate > 0 and own_report or object.rate > 0 and admin_report %}

        {% for type, value in totals.paid_tasks.items %}
          {% for rate, item in value.rates.items %}
          <tr>
            <td>&nbsp;</td>
            <td colspan="4">{{ value.action }} ({% trans "registered tasks" %})</td>
            <td class="number">{{ item.amount }}</td>
            <td class="number">{{ rate }} {{ object.currency }}</td>
            <td class="number">{{ item.subtotal }} {{ object.currency }}</td>
          </tr>
          {% endfor %}
        {% endfor %}

        <tr class="total">
          <td>&nbsp;</td>
          <td colspan="6">{% trans "Total" %}</td>
          <td class="number">{{ totals.all|floatformat:4 }} {{ object.currency }}</td>
        </tr>
      {% endif %}
    {% endif %}
    </tbody>
  </table>
  {% else %}
    <div id="message">{% trans "Please select a valid user." %}</div>
  {% endif %}
</body>
</html>
