{% load i18n %}
{% load django_ledger %}

<div class="table-container">
    <table class="table is-narrow is-fullwidth is-bordered django-ledger-table-bottom-margin-75">
        <thead>
        <tr class="has-text-centered is-error">
            <th>Dated Posted</th>
            <th>Description</th>
            <th>Amount</th>
            <th>Activity</th>
            <th>Entity Unit</th>
            <th>Map To</th>
            <th>TX</th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>
        {% for imported_tx in imported_txs %}
            <tr id="staged-tx-{{ imported_tx.uuid }}">
                <td>{{ imported_tx.date_posted }}</td>
                <td>{{ imported_tx.name }}</td>
                <td class="{% if imported_tx.get_amount < 0.00 %}has-text-danger{% endif %} has-text-centered">
                    {% currency_symbol %}{{ imported_tx.get_amount }}</td>
                <td>{% if imported_tx.activity %}
                    {{ imported_tx.get_activity_display }}
                {% endif %}</td>
                <td>{% if imported_tx.entity_unit %}{{ imported_tx.entity_unit }}{% endif %}</td>
                <td>{{ imported_tx.account_model }}</td>
                <td>{{ imported_tx.transaction_model }}</td>
                <td class="has-text-centered">
                    <div class="dropdown is-hoverable is-right">
                        <div class="dropdown-trigger">
                            <button class="button is-small" aria-haspopup="true" aria-controls="actions-{{ imported_tx.uuid }}">
                                <span>{% trans 'Actions' %}</span>
                                <span class="icon is-small">{% icon 'mdi:chevron-down' 14 %}</span>
                            </button>
                        </div>
                        <div class="dropdown-menu" id="actions-{{ imported_tx.uuid }}" role="menu">
                            <div class="dropdown-content">
                                <a href="{% url 'django_ledger:je-detail' entity_slug=import_job_model.entity_slug ledger_pk=imported_tx.transaction_model.journal_entry.ledger_id je_pk=imported_tx.transaction_model.journal_entry_id %}"
                                   class="dropdown-item">{% trans 'View JE' %}</a>
                                {% if imported_tx.has_receipt %}
                                    <a href="{% url 'django_ledger:receipt-detail' entity_slug=import_job_model.entity_slug receipt_pk=imported_tx.receiptmodel.uuid %}"
                                       class="dropdown-item">{% trans 'View Receipt' %}</a>
                                {% endif %}
                                <hr class="dropdown-divider">
                                <form method="post" action="{% url 'django_ledger:data-import-staged-tx-undo' entity_slug=import_job_model.entity_slug job_pk=import_job_model.uuid staged_tx_pk=imported_tx.uuid %}">
                                    {% csrf_token %}
                                    <button type="submit" class="dropdown-item has-text-danger">{% trans 'Undo Import' %}</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>


