{% extends "base.html" %}

{% block title %}
  Équilibre
{% endblock title %}

{% block main %}

  <section class="g-Section">
    {% if exceeding_payers %}
      <ul class="g-Balance__ExceedingPayers">
        {% for exceeding_payer in exceeding_payers %}
          <li class="g-Balance__ExceedingPayer">
            {{ exceeding_payer.0 }} : +{{ exceeding_payer.1 | euros() }}
          </li>
        {% endfor %}
      </ul>
    {% else %}
      <p class="g-Paragraph">
        Les paiements sont équilibrés.
      </p>
    {% endif %}

    {% if incomes_from %}
      <h1 class="g-Title">
        Revenus
      </h1>

      <div class="g-Table">
        <div class="g-Table__Row g-Table__Row--Header">
          <span class="g-Table__Cell"></span>
          <span class="g-Table__Cell">Montant</span>
          <span class="g-Table__Cell">Part</span>
        </div>
        {% for user_income in user_incomes %}
          <div class="g-Table__Row">
            <span class="g-Table__Cell">
              {{ user_income.0 }}
            </span>
            <span class="g-Table__Cell g-Table__NumericCell">
              {{ user_income.1 | euros() }}
            </span>
            <span class="g-Table__Cell g-Table__NumericCell">
              {% if total_income > 0 %}
                {{ user_income.1 / total_income * 100 | round() }} %
              {% else %}
                –
              {% endif %}
            </span>
          </div>
        {% endfor %}
        <div class="g-Table__Row">
          <span class="g-Table__Cell">
            Total
          </span>
          <span class="g-Table__Cell g-Table__NumericCell">
            {{ total_income | euros() }}
          </span>
          <span class="g-Table__Cell g-Table__NumericCell">
            100 %
          </span>
        </div>
      </div>
    {% endif %}

    <h1 class="g-Title">
      Paiements
    </h1>

    <div class="g-Table">
      <div class="g-Table__Row g-Table__Row--Header">
        <span class="g-Table__Cell"></span>
        <span class="g-Table__Cell">Montant</span>
        <span class="g-Table__Cell">Part</span>
      </div>
      {% for user_payment in user_payments %}
        <div class="g-Table__Row">
          <span class="g-Table__Cell">
            {{ user_payment.0 }}
          </span>
          <span class="g-Table__Cell g-Table__NumericCell">
            {{ user_payment.1 | euros() }}
          </span>
          <span class="g-Table__Cell g-Table__NumericCell">
            {% if total_payments > 0 %}
              {{ user_payment.1 / total_payments * 100 | round() }} %
            {% else %}
              –
            {% endif %}
          </span>
        </div>
      {% endfor %}
      <div class="g-Table__Row">
        <span class="g-Table__Cell">
          Total
        </span>
        <span class="g-Table__Cell g-Table__NumericCell">
          {{ total_payments | euros() }}
        </span>
        <span class="g-Table__Cell g-Table__NumericCell">
          100 %
        </span>
      </div>
    </div>
  </div>

{% endblock main %}