{% load i18n %}
{% load translations %}
{% load humanize %}
{% load icons %}

  {% with billing.plan as plan %}
  <table class="table">
  <tr>
    <th>{% trans "Current plan" %}</th>
    <td>
      {{ plan.name }} ({{ billing.get_state_display }})

    </td>
    <td>
        {% if  payment_enabled and billing.can_be_paid %}
        <a href="{% url 'create-billing' %}?billing={{ billing.pk }}&amp;upgrade=1" class="btn btn-primary pull-right flip">
        {% trans "Change plan" %}
        </a>
        {% endif %}
    </td>
  </tr>
  {% if billing.expiry %}
    <tr>
      <th>{% trans "Trial expiry date" %}</th>
      <td>{{ billing.expiry|naturaltime }}</td>
      <td>
        {% if user.is_superuser %}
          <a href="{{ billing.get_absolute_url }}" class="btn btn-primary pull-right flip link-post" data-params='{"extend": 1}'>{% trans "Extend trial" %}</a>
        {% endif %}
      </td>
    </tr>
  {% endif %}
  {% if billing.removal %}
    <tr>
      <th>{% trans "Scheduled removal" %}</th>
      <td>{{ billing.removal|naturaltime }}</td>
      <td>
        {% if billing.is_trial and user.is_superuser %}
          <a href="{{ billing.get_absolute_url }}" class="btn btn-primary pull-right flip link-post" data-params='{"extend": 1}'>{% trans "Extend trial" %}</a>
        {% endif %}
      </td>
    </tr>
  {% endif %}
  <tr>
    <th>{% trans "Monthly price" %}</th>
    <td>
        {{ plan.price|intcomma }} EUR
    </td>
    <td>
        {% if payment_enabled and billing.can_be_paid and plan.price %}
        <form class="form-inline" method="post" action="{% url 'create-billing' %}">
        {% csrf_token %}
        <input type="hidden" name="plan" value="{{ plan.id }}" />
        <input type="hidden" name="billing" value="{{ billing.id }}" />
        <input type="hidden" name="period" value="m" />
        <input type="submit" value="{% trans "New payment" %}" class="btn btn-primary pull-right flip" />
        </form>
        {% endif %}
    </td>
  </tr>
  <tr>
    <th>{% trans "Yearly price" %}</th>
    <td>{{ plan.yearly_price|intcomma }} EUR</td>
    <td>
        {% if payment_enabled and billing.can_be_paid and plan.yearly_price %}
        <form class="form-inline" method="post" action="{% url 'create-billing' %}">
        {% csrf_token %}
        <input type="hidden" name="plan" value="{{ plan.id }}" />
        <input type="hidden" name="billing" value="{{ billing.id }}" />
        <input type="hidden" name="period" value="y" />
        <input type="submit" value="{% trans "New payment" %}" class="btn btn-primary pull-right flip" />
        </form>
        {% endif %}
    </td>
  </tr>
  <tr><th>{% trans "Strings limit" %}</th>
  {% with plan.limit_strings as max and plan.display_limit_strings as total and billing.count_strings as used %}
  {% include "billing/used.html" %}
  {% endwith %}
  </tr>
  <tr><th>{% trans "Languages limit" %}</th>
  {% with plan.limit_languages as max and plan.display_limit_languages as total and billing.count_languages as used %}
  {% include "billing/used.html" %}
  {% endwith %}
  </tr>
  <tr><th>{% trans "Last invoice" %}</th>
  <td colspan="2">{{ billing.last_invoice }}</td></tr>
  <tr><th>{% trans "Projects limit" %}</th>
  {% with plan.limit_projects as max and plan.display_limit_projects as total and billing.all_projects|length as used %}
  {% include "billing/used.html" %}
  {% endwith %}
  </tr>
  {% if billing.all_projects %}
    <tr>
      <td colspan="3">
        {% include "snippets/list-objects.html" with objects=billing.all_projects hide_details=1 %}
      </td>
    </tr>
  {% else %}
    <tr>
      <th>{% trans "Projects" %}</th>
      <td><em>{% trans "No projects currently assigned!" %}</em></td>
      <td>
        {% if billing.is_active %}
          <a class="btn btn-primary billing-add-project pull-right flip" href="{% url 'create-project' %}?billing={{ billing.pk }}">{% trans "Add new translation project" %}</a>
        {% endif %}
      </td>
    </tr>
  {% endif %}
  {% if user.is_superuser %}
    <tr>
      <th>{% trans "Owners" %}</th>
      <td colspan="2">
        {% for owner in billing.owners.all %}
          <p>
            <span class="profile-icon">{% icon "account.svg" %}</span>
            <span class="middle-dot-divider">
              {{ owner }}
            </span>
            <span class="middle-dot-divider">
              <a href="{{ owner.get_absolute_url }}">@{{ owner.username }}</a>
            </span>
            <span class="middle-dot-divider">
              <a href="mailto:{{ owner.email }}">{{ owner.email }}</a>
            </span>
            {% if user.is_superuser %}
            <span class="middle-dot-divider">
              <a href="{% url "manage-users-check" %}?email={{ owner.email|urlencode }}">{% trans "Check user access" %}</a>
            </span>
            {% endif %}
          </p>
        {% endfor %}
      </td>
    </tr>
  {% endif %}
  </table>
  {% endwith %}
