{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load eventurl %}
{% load urlreplace %}
{% load money %}
{% load bootstrap3 %}
{% block title %}{% trans "Refunds" %}{% endblock %}
{% block content %}
    <h1>{% trans "Refunds" %}</h1>
    <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-xs-6">
                    {% bootstrap_field filter_form.status %}
                </div>
                <div class="col-md-6 col-xs-6">
                    {% bootstrap_field filter_form.provider %}
                </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>
    {% if not filter_form.filtered and refunds|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    No refunds are currently open.
                {% endblocktrans %}
            </p>
        </div>
    {% else %}
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>
                        #
                        <a href="?{% url_replace request 'ordering' '-order' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'order' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th>
                        {% trans "Payment provider" %}
                        <a href="?{% url_replace request 'ordering' '-provider' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'provider' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th>
                        {% trans "Start date" %}
                        <a href="?{% url_replace request 'ordering' '-created' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'created' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th>
                        {% trans "Source" %}
                        <a href="?{% url_replace request 'ordering' '-source' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'source' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th>
                        {% trans "Status" %}
                        <a href="?{% url_replace request 'ordering' '-state' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'state' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th class="text-right flip">
                        {% trans "Amount" %}
                        <a href="?{% url_replace request 'ordering' '-amount' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'amount' %}"><i class="fa fa-caret-up"></i></a></th>
                    </th>
                    <th class="text-right flip">{% trans "Actions" %}</th>
                </tr>
                </thead>
                <tbody>
                {% for r in refunds %}
                    <tr>
                        <td>
                            <strong>
                                <a href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=r.order.code %}">
                                    {{ r.order.code }}</a>-R-{{ r.local_id }}
                            </strong>
                            {% if r.order.testmode %}
                                <span class="label label-warning">{% trans "TEST MODE" %}</span>
                            {% endif %}
                        </td>
                        <td>
                            {{ r.payment_provider.verbose_name }}
                        </td>
                        <td>{{ r.created|date:"SHORT_DATETIME_FORMAT" }}</td>
                        <td>{{ r.get_source_display }}</td>
                        <td>
                            <span class="label label-{% if r.state == "external" or r.state == "transit" or r.state == "created" %}warning{% elif r.state == "done" %}success{% else %}danger{% endif %}">
                                {{ r.get_state_display }}
                            </span>
                        </td>
                        <td class="text-right flip">
                            {{ r.amount|money:request.event.currency }}
                        </td>
                        <td class="text-right flip">
                            {% if r.state == "transit" or r.state == "created" %}
                                <a href="{% url "control:event.order.refunds.cancel" event=request.event.slug organizer=request.event.organizer.slug code=r.order.code refund=r.pk %}?next={{ request.get_full_path|urlencode }}"
                                   class="btn btn-danger btn-xs" data-toggle="tooltip">
                                    <span class="fa fa-times"></span>
                                    {% trans "Cancel" %}
                                </a>
                                <a href="{% url "control:event.order.refunds.done" event=request.event.slug organizer=request.event.organizer.slug code=r.order.code refund=r.pk %}?next={{ request.get_full_path|urlencode }}"
                                   class="btn btn-primary btn-xs" data-toggle="tooltip">
                                    <span class="fa fa-check"></span>
                                    {% trans "Confirm as done" %}
                                </a>
                                {% elif r.state == "external" %}
                                <a href="{% url "control:event.order.refunds.cancel" event=request.event.slug organizer=request.event.organizer.slug code=r.order.code refund=r.pk %}?next={{ request.get_full_path|urlencode }}"
                                   class="btn btn-default btn-xs" data-toggle="tooltip">
                                    <span class="fa fa-times"></span>
                                    {% trans "Ignore" %}
                                </a>
                                <a href="{% url "control:event.order.refunds.process" event=request.event.slug organizer=request.event.organizer.slug code=r.order.code refund=r.pk %}?next={{ request.get_full_path|urlencode }}"
                                   class="btn btn-primary btn-xs" data-toggle="tooltip">
                                    <span class="fa fa-check"></span>
                                    {% trans "Process refund" %}
                                </a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
