{% extends "pretixcontrol/organizers/base.html" %}
{% load i18n %}
{% load urlreplace %}
{% load bootstrap3 %}
{% load money %}
{% block inner %}
    <h1>
        {% trans "Issued gift cards" %}
    </h1>
    {% if giftcards|length == 0 and not filter_form.filtered %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't issued any gift cards yet. You can either set up a product in an event shop to sell gift cards,
                    or you can manually issue gift cards.
                {% endblocktrans %}
            </p>

            <a href="{% url "control:organizer.giftcard.add" organizer=request.organizer.slug %}"
                    class="btn btn-default btn-lg"><i class="fa fa-plus"></i> {% trans "Manually issue a gift card" %}
            </a>
        </div>
    {% else %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Filter" %}</h3>
            </div>
            <form class="panel-body filter-form" action="" method="get">
                <div class="row">
                    <div class="col-md-6 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.query %}
                    </div>
                    <div class="col-md-3 col-sm-6 col-xs-6">
                        {% bootstrap_field filter_form.testmode %}
                    </div>
                    <div class="col-md-3 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>
                        {% trans "Filter" %}
                    </button>
                </div>
            </form>
        </div>
        <p>
            <a href="{% url "control:organizer.giftcard.add" organizer=request.organizer.slug %}"
                    class="btn btn-default"><i class="fa fa-plus"></i> {% trans "Manually issue a gift card" %}</a>
        </p>
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "Gift card code" %}
                        <a href="?{% url_replace request 'ordering' '-code' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'code' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Creation date" %}
                        <a href="?{% url_replace request 'ordering' '-issuance' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'issuance' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Expiry date" %}
                        <a href="?{% url_replace request 'ordering' '-expires' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'expires' %}"><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 value" %}
                        <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 g in giftcards %}
                    <tr>
                        <td>
                            <a href="{% url "control:organizer.giftcard" organizer=request.organizer.slug giftcard=g.id %}">
                                <strong>{{ g.secret }}</strong></a>
                            {% if g.testmode %}
                                <span class="label label-warning">{% trans "TEST MODE" %}</span>
                            {% endif %}
                            {% if g.expired %}
                                <span class="label label-danger">{% trans "Expired" %}</span>
                            {% endif %}
                        </td>
                        <td>{{ g.issuance|date:"SHORT_DATETIME_FORMAT" }}</td>
                        <td>{% if g.expires %}{{ g.expires|date:"SHORT_DATETIME_FORMAT" }}{% endif %}</td>
                        <td>{% if g.last_tx %}{{ g.last_tx|date:"SHORT_DATETIME_FORMAT" }}{% endif %}</td>
                        <td class="text-right">
                            {{ g.cached_value|money:g.currency }}
                        </td>
                        <td class="text-right">
                            <a href="{% url "control:organizer.giftcard" organizer=request.organizer.slug giftcard=g.id %}"
                                    class="btn btn-default btn-sm" data-toggle="tooltip" title="{% trans "Details" %}">
                                <i class="fa fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
