{% extends 'oscar/dashboard/layout.html' %}
{% load currency_filters %}
{% load sorting_tags %}
{% load i18n %}

{% block title %}
    {{ description }} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
        </li>
        {% if form.is_bound %}
            <li>
                <a href="{% url 'dashboard:voucher-list' %}">{% trans "Vouchers" %}</a>
            </li>
        {% endif %}
        <li class="active">{{ description }}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <a href="{% url 'dashboard:voucher-create' %}" class="btn btn-primary btn-lg pull-right"><i class="icon-plus"></i> {% trans "Create new voucher" %}</a>
        <h1>{% trans "Vouchers" %}</h1>
    </div>
{% endblock header %}


{% block dashboard_content %}
    {% block page_head %}
        <div class="table-header">
            <h3><i class="icon-search icon-large"></i>{% trans "Search" %}</h3>
        </div>
        <div class="well">
            <form method="get" class="form-inline">
                {% include 'oscar/dashboard/partials/form_fields_inline.html' with form=form %}
                <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Searching...' %}">{% trans "Search" %}</button>
                <a href="{% url 'dashboard:voucher-list' %}" class="btn btn-default">{% trans "Reset" %}</a>
            </form>
        </div>
    {% endblock page_head %}

    {% block voucher_table %}
        <table class="table table-striped table-bordered table-hover">
            <caption><i class="icon-money icon-large"></i>{{ description }}</caption>
            {% if vouchers %}
                {% block table_head %}
                    <tr>
                        <th>{% trans "Name" %}</th>
                        <th>{% trans "Code" %}</th>
                        <th>{% trans "Status" %}</th>
                        <th>{% anchor 'num_basket_additions' _("Num baskets") %}</th>
                        <th>{% anchor 'num_orders' _("Num orders") %}</th>
                        <th>{% anchor 'date_created' _("Date created") %}</th>
                        <th></th>
                    </tr>
                {% endblock table_head %}
                {% for voucher in vouchers %}
                    {% block table_row %}
                        <tr>
                            <td><a href="{% url 'dashboard:voucher-stats' voucher.id %}">{{ voucher.name }}</a></td>
                            <td>
                                <span class="label label-default">{{ voucher.code }}</span>
                            </td>
                            <td>
                                {% if voucher.is_active %}
                                    <span class="label label-success">{% trans "Active" %}</span>
                                {% else %}
                                    <span class="label label-default">{% trans "Inactive" %}</span>
                                {% endif %}
                            </td>
                            <td>{{ voucher.num_basket_additions }}</td>
                            <td>{{ voucher.num_orders }}</td>
                            <td>{{ voucher.date_created }}</td>
                            <td>
                                {% block row_actions %}
                                    <div class="btn-toolbar">
                                        <div class="btn-group">
                                            <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="true">
                                                {% trans "Actions" %}
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right">
                                                <li><a href="{% url 'dashboard:voucher-stats' pk=voucher.id %}">{% trans "Stats" %}</a></li>
                                                <li><a href="{% url 'dashboard:voucher-update' pk=voucher.id %}">{% trans "Edit" %}</a></li>
                                                <li><a href="{% url 'dashboard:voucher-delete' pk=voucher.id %}">{% trans "Delete" %}</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                {% endblock row_actions %}
                            </td>
                        </tr>
                    {% endblock table_row %}
                {% endfor %}
            {% else %}
                <tr><td>{% trans "No vouchers found." %}</td></tr>
            {% endif %}
        </table>
    {% endblock voucher_table %}
{% include "oscar/dashboard/partials/pagination.html" %}
{% endblock dashboard_content %}
