{% extends "pretixcontrol/organizers/base.html" %}
{% load i18n %}
{% load urlreplace %}
{% load bootstrap3 %}
{% load money %}
{% block title %}Wallets{% endblock %}
{% block inner %}
    <h1>Wallets</h1>
    {% if wallets|length == 0 and not filter_form.filtered %}
        <div class="empty-collection">
            <p>
                No wallets have been created yet.
            </p>
        </div>
    {% else %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Filter</h3>
            </div>
            <form class="panel-body filter-form" action="" method="get">
                <div class="row">
                    <div class="col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.query %}
                    </div>
                    <div class="col-sm-6 col-xs-6">
                        {% bootstrap_field filter_form.state %}
                    </div>
                </div>
                <div class="text-right">
                    <button class="btn btn-primary btn-lg" type="submit">
                        <span class="fa fa-filter"></span>
                        Filter
                    </button>
                </div>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "PAN" %}
                        <a href="?{% url_replace request 'ordering' '-id' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'id' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Customer" %}
                        <a href="?{% url_replace request 'ordering' '-customer' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'customer' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Creation date" %}
                        <a href="?{% url_replace request 'ordering' '-created_at' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'created_at' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Last transaction" %}
                        <a href="?{% url_replace request 'ordering' '-last_tx' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'last_tx' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th class="text-right">{% trans "Current balance" %}
                        <a href="?{% url_replace request 'ordering' '-value' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'value' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for w in wallets %}
                    <tr>
                        <td>
                            <strong><a href="{% url "plugins:pretix_wallet:wallet" organizer=request.organizer.slug pan=w.pan %}">{{ w.pan }}</a></strong>
                        </td>
                        <td>
                            {% if w.customer %}
                                <a href="{% url "control:organizer.customer" organizer=request.organizer.slug customer=w.customer.identifier %}">
                                    {{ w.customer.name }}
                                </a>
                            {% endif %}
                        </td>
                        <td>{{ w.created_at|date:"SHORT_DATETIME_FORMAT" }}</td>
                        <td>{% if w.last_tx %}{{ w.last_tx|date:"SHORT_DATETIME_FORMAT" }}{% endif %}</td>
                        <td class="text-right">
                            {{ w.cached_balance|money:w.currency }}
                        </td>
                        <td class="text-right">

                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
