{% load i18n %}
{% load rich_text %}
{% load staticfiles %}
<div class="table-responsive">
    {% csrf_token %}
    <table class="table table-condensed transaction-list" data-url="{% if request.event %}{% url "plugins:banktransfer:import.action" event=request.event.slug organizer=request.organizer.slug %}{% else %}{% url "plugins:banktransfer:import.action" organizer=request.organizer.slug %}{% endif %}">
        <thead>
        <tr>
            <th></th>
            <th>{% trans "Date" %}</th>
            <th>{% trans "Payer and reference" %}</th>
            <th>{% trans "Amount" %}</th>
            <th>{% trans "Result" %}</th>
            <th>{% trans "Order" %}</th>
        </tr>
        </thead>
        <tbody>
        {% for trans in list %}
            <tr data-id="{{ trans.id }}">
                <td class="actions">
                    {% if trans.order and trans.state == 'invalid' %}
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="accept"
                                data-toggle="tooltip" title="{% trans "Accept anyway" %}" data-placement="right">
                                <span class="fa fa-check"></span>
                            </button>
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="discard"
                                data-toggle="tooltip" title="{% trans "Discard" %}">
                                <span class="fa fa-trash"></span>
                            </button>
                        </div>
                    {% elif trans.state == 'nomatch' %}
                        <input type="text" class="form-control" placeholder="{% trans "Order code" %}">
                        <div class="btn-group" role="group">
                            <button class="btn btn-default" type="button" name="action_{{ trans.id }}"
                                    value="assign" data-toggle="tooltip" title="{% trans "Assign to order" %}" data-placement="right">
                                <span class="fa fa-check"></span>
                            </button>
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="discard"
                                data-toggle="tooltip" title="{% trans "Discard" %}">
                                <span class="fa fa-trash"></span>
                            </button>
                        </div>
                    {% elif trans.state == 'error' or trans.state == 'already' %}
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="retry"
                                data-toggle="tooltip" title="{% trans "Retry" %}" data-placement="right">
                                <span class="fa fa-refresh"></span>
                            </button>
                            <button type="button" class="btn btn-default" name="action_{{ trans.id }}" value="discard"
                                data-toggle="tooltip" title="{% trans "Discard" %}">
                                <span class="fa fa-trash"></span>
                            </button>
                        </div>
                    {% endif %}
                </td>
                <td>{{ trans.date }}</td>
                <td>
                    {{ trans.payer }}<br/>
                    {{ trans.reference }}
                    <div class="comment-box" data-plain="{{ trans.comment }}">
                        <strong>{% trans "Comment:" %}</strong>
                        <span class="comment">{{ trans.comment|rich_text }}</span>
                        <a href="#" class="comment-modify btn btn-default btn-xs">
                            <span class="fa fa-edit"></span>
                        </a>
                    </div>
                </td>
                <td>{{ trans.amount|floatformat:2 }}</td>
                <td>
                    {% if trans.message %}
                        {% trans trans.message %}
                    {% elif trans.state == 'nomatch' %}
                        {% trans "No order code detected" %}
                    {% elif trans.state == 'invalid' %}
                        {% trans "Invalid for this order" %}
                    {% elif trans.state == 'error' %}
                        {% trans "Error while processing" %}
                    {% elif trans.state == 'valid' %}
                        {% trans "The order is already marked as paid" %}
                    {% elif trans.state == 'already' %}
                        {% trans "Order already paid" %}
                    {% endif %}
                </td>
                <td>
                    {% if trans.order %}
                        <a href="{% url "control:event.order" event=trans.order.event.slug organizer=request.organizer.slug code=trans.order.code %}"
                            data-toggle="tooltip" title="{{ trans.order.total|floatformat:2 }} {{ trans.order.event.currency }}">
                            {% if not request.event %}
                                {{ trans.order.event.slug|upper }}-{{ trans.order.code }}
                            {% else %}
                                {{ trans.order.code }}
                            {% endif %}
                        </a>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
