{% extends 'dashboard/layout.html' %}

{% load currency_filters %}
{% load sorting_tags %}
{% load i18n %}

{% block title %}
    {% trans "Offer management" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{{ homepage_url }}">{% trans "Dashboard" %}</a>
            <span class="divider">/</span>
        </li>
        <li class="active">{% trans "Offer management" %}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <a href="{% url 'dashboard:offer-metadata' %}" class="btn btn-primary btn-large pull-right"><i class="icon-plus"></i> {% trans "Create new offer" %}</a>
        <h1>{% trans "Offer management" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    <div class="well">
        <form action="." method="get" class="form-inline">
            {% include 'partials/form_fields_inline.html' with form=form %}
            <button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
        </form>
    </div>

    <form action="." method="post" class="order_table">
        {% csrf_token %}
        <table class="table table-striped table-bordered">
            <caption>
                <i class="icon-gift icon-large"></i>{{ queryset_description }}
                {% if is_filtered %}
                    <a href="{% url 'dashboard:offer-list' %}" >{% trans "Reset" %}</a>
                {% endif %}
            </caption>
            {% if offers %}
                <tr>
                    <th>{% anchor 'name' _('Offer name') %}</th>
                    <th>{% anchor 'start_date' _('Start date') %}</th>
                    <th>{% anchor 'end_date' _('End date') %}</th>
                    <th>{% trans "Incentive" %}</th>
                    <th>{% trans "Condition" %}</th>
                    <th>{% trans "Is available?" %}</th>
                    <th>{% trans "Restrictions" %}</th>
                    <th>{% anchor 'num_applications' _('Uses') %}</th>
                    <th>{% anchor 'total_discount' _('Cost') %}</th>
                    <th></th>
                </tr>
                {% for offer in offers %}
                    <tr>
                        <td><a href="{% url 'dashboard:offer-detail' pk=offer.pk %}">{{ offer.name }}</a></td>
                        <td>{{ offer.start_date|default:"-" }}</td>
                        <td>{{ offer.end_date|default:"-" }}</td>
                        <td>{{ offer.benefit.description|safe }}</td>
                        <td>{{ offer.condition.description|safe }}</td>
                        <td>{% if offer.is_available %}
                                <span class="label label-success">{% trans "Yes" %}</span>
                            {% else %}
                                <span class="label label-important">{% trans "No" %}</span>
                            {% endif %}
                        </td>
                        <td>
                            {% for restriction in offer.availability_restrictions %}
                                {% if not restriction.is_satisfied %}
                                    <label class="label label-important">
                                        {{ restriction.description }}
                                    </label>
                                {% else %}
                                    {{ restriction.description }}</br>
                                {% endif %}
                            {% endfor %}
                        </td>
                        <td>{{ offer.num_applications }}</td>
                        <td>{{ offer.total_discount|currency }}</td>
                        <td>
                            <div class="btn-toolbar">
                                <div class="btn-group">
                                    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                                        {% trans "Actions" %}
                                        <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu pull-right">
                                        <li><a class="" href="{% url 'offer:detail' slug=offer.slug %}">{% trans "Browse" %}</a></li>
                                        <li><a class="" href="{% url 'dashboard:offer-detail' pk=offer.pk %}">{% trans "Stats" %}</a></li>
                                        <li><a class="" href="{% url 'dashboard:offer-metadata' pk=offer.pk %}">{% trans "Edit" %}</a></li>
                                        <li><a class="" href="{% url 'dashboard:offer-delete' pk=offer.pk %}">{% trans "Delete" %}</a></li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                {% endfor %}

            {% else %}
                <tr><td>{% trans "No offers found." %}</td></tr>
            {% endif %}
        </table>
        {% include "partials/pagination.html" %}
    </form>
{% endblock dashboard_content %}
