{% extends "rattingtax/base.html" %}
{% load i18n humanize %}
{% block header_nav_collapse_right %}
    <a href="{% url 'rattingtax:connect' %}" class="btn btn-success btn-sm text-nowrap">
      {% trans "Connect Corp Token" %}
    </a>
{% endblock %}
{% block details %}
<div class="card mt-3">
  <div class="card-header d-flex justify-content-between align-items-center">
    <strong>{% trans "Ratting Tax Summary" %}</strong>
    <span class="text-muted small">
      {% trans "Tax reduction" %}: <strong>{{ tax_reduction }} Isk</strong>
    </span>
    <form method="get" class="d-flex gap-2 mb-0">
        <select name="corp" class="form-select form-select-sm text-nowrap">
            <option value="">{% trans "All corporations" %}</option>
            {% for c in corps %}
            <option value="{{ c.corporation_id }}" {% if selected_corp == c.corporation_id %}selected{% endif %}>
                {{ c.name }}{% if c.ticker %} ({{ c.ticker }}){% endif %}
            </option>
            {% endfor %}
        </select>

        <select name="month" class="form-select form-select-sm text-nowrap">
          {% for opt in month_options %}
            <option value="{{ opt.value }}" {% if selected_month == opt.value %}selected{% endif %}>
              {{ opt.label }}
            </option>
          {% endfor %}
        </select>

        <select name="year" class="form-select form-select-sm text-nowrap">
            {% for y in years %}
            <option value="{{ y }}" {% if selected_year == y %}selected{% endif %}>{{ y }}</option>
            {% endfor %}
        </select>

        <button class="btn btn-primary btn-sm text-nowrap" type="submit">
            {% trans "Filter" %}
        </button>
    </form>
  </div>

  <div class="card-body">
    {% if rows %}
      <div class="table-responsive">
        <table class="table table-sm align-middle">
          <thead>
            <tr>
              <th>{% trans "Corporation" %}</th>
              <th class="text-end">{% trans "Total (month)" %}</th>
              <th class="text-end">{% trans "Corp rate (%)" %}</th>
              <th class="text-end">{% trans "Alliance rate (%)" %}</th>
              <th class="text-end">{% trans "Alliance tax" %}</th>
            </tr>
          </thead>
          <tbody>
            {% for r in rows %}
              <tr>
                <td class="text-nowrap">
                  {% if r.corp.logo_url %}
                   <img src="{{ r.corp.logo_url }}" alt="" style="height:20px;width:20px;border-radius:3px;margin-right:6px;">
                  {% endif %}
                  {{ r.corp.name }}{% if r.corp.ticker %} [{{ r.corp.ticker }}]{% endif %}
                </td>
                <td class="text-end">{{ r.corp_tax_amount }} Isk</td>
                <td class="text-end">{{ r.corp_rate }}%</td>
                <td class="text-end">{{ r.alliance_rate }}%</td>
                <td class="text-end">{{ r.alliance_tax }} Isk</td>
              </tr>
            {% empty %}
              <tr>
                <td colspan="5" class="text-center text-muted py-4">
                  {% trans "No data for selected filters." %}
                </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    {% else %}
      <p class="text-muted mb-0">{% trans "No data for selected period/corporation(s)." %}</p>
    {% endif %}
  </div>
</div>
{% endblock %}
