{% load i18n l10n fontawesome_5 humanize %}
<div id="eco-account-deductions" class="card">
    <div class="card-header rlp-r">
        <div class="row">
            <div class="col-sm-6">
                <h5>
                    <span class="badge badge-light">{{obj.deductions.count}}</span>
                    {% trans 'Eco Account Deductions' %}
                </h5>
            </div>
            <div class="col-sm-6">
                <div class="d-flex justify-content-end">
                    {% if is_default_member and has_access  %}
                    <button class="btn btn-outline-default btn-modal" data-form-url="{% url 'intervention:new-deduction' obj.id %}" title="{% trans 'Add new deduction' %}">
                        {% fa5_icon 'plus' %}
                        {% fa5_icon 'tree' %}
                    </button>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    <div class="card-body {% if tables_scrollable %}scroll-300{% endif %} p-2">
        <table class="table table-hover">
            <thead>
            <tr>
                <th class="w-25" scope="col">
                    {% trans 'Account Identifier' %}
                </th>
                <th scope="col">
                    {% trans 'Amount' %}
                </th>
                <th scope="col">
                    {% trans 'Created' %}
                </th>
                {% if is_default_member and has_access %}
                    <th class="w-10" scope="col">
                        <span class="float-right">
                            {% trans 'Action' %}
                        </span>
                    </th>
                {% endif %}
            </tr>
            </thead>
            <tbody>
            {% for deduction in obj.deductions.all %}
            <tr {% if deduction.account.deleted %}class="align-middle alert-danger" title="{% trans 'Eco-account deleted! Deduction invalid!' %}" {% elif not deduction.account.recorded %}class="align-middle alert-danger" title="{% trans 'Eco-account not recorded! Deduction invalid!' %}"  {% endif %}>
                <td class="align-middle">
                    <a href="{% url 'compensation:acc:detail' deduction.account.id %}">
                        {% if deduction.account.deleted or not deduction.account.recorded %}
                        {% fa5_icon 'exclamation-triangle' %}
                        {% endif %}
                        {{ deduction.account.identifier }}
                    </a>
                </td>
                <td class="align-middle">{{ deduction.surface|floatformat:2|intcomma }} m²</td>
                <td class="align-middle">{{ deduction.created.timestamp|default_if_none:""|naturalday}}</td>
                <td class="align-middle float-right">
                    {% if is_default_member and has_access  %}
                    <button data-form-url="{% url 'intervention:edit-deduction' obj.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit Deduction' %}">
                        {% fa5_icon 'edit' %}
                    </button>
                    <button data-form-url="{% url 'intervention:remove-deduction' obj.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Deduction' %}">
                        {% fa5_icon 'trash' %}
                    </button>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>