{% extends 'autosrp/base.html' %}
{% load i18n humanize %}
{% block content %}
<div class="container-xxl py-3">
    <div class="d-flex flex-wrap align-items-center justify-content-between mb-3 gap-2">
        <h3 class="m-0">{% trans "Doctrine Rewards" %}</h3>
        {% if perms.autosrp.manage %}
        <a class="btn btn-primary btn-sm" href="{% url 'autosrp:reward-create' %}">{% trans "New Reward" %}</a>
        {% endif %}
    </div>

    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-sm align-middle mb-0">
                    <thead class="table-dark">
                    <tr>
                        <th style="width: 28%;">{% trans "Doctrine" %}</th>
                        <th style="width: 28%;">{% trans "Ship" %}</th>
                        <th style="width: 20%;">{% trans "Base Reward (ISK)" %}</th>
                        <th style="width: 16%;">{% trans "Penalty Scheme" %}</th>
                        <th style="width: 8%;"></th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for r in object_list %}
                    <tr>
                        <td>
                            <div class="fw-semibold">{{ r.doctrine_name|default:r.doctrine_id }}</div>
                        </td>
                        <td>
                            <div class="fw-semibold">{{ r.ship_name|default:r.ship_type_id }}</div>
                        </td>
                        <td>
                            <span class="fw-semibold">{{ r.base_reward_isk|floatformat:2|intcomma }}</span>
                        </td>
                        <td>
                            {% if r.penalty_scheme %}
                            {{ r.penalty_scheme.name }}
                            {% else %}
                            <span class="text-muted">—</span>
                            {% endif %}
                        </td>
                        <td class="text-end">
                            {% if perms.autosrp.manage %}
                            <a href="{% url 'autosrp:reward-update' r.pk %}" class="btn btn-outline-secondary btn-sm">{% trans "Edit" %}</a>
                        </td>
                        <td class="text-end">
                            <form method="post" action="{% url 'autosrp:reward-delete' r.pk %}" onsubmit="return confirm('Delete this reward?');">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
                            </form>
                            {% endif %}
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="5" class="text-center text-muted py-4">
                            {% trans "No rewards yet." %}
                        </td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
