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

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

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

{% block header %}
<div class="page-header">
	<h1>{% trans "Offer management" %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}
<div class="well well-info">
    <div class="sub-header">
		<h3>Search</h3>
    </div>
    <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>
		<a href="{% url dashboard:offer-list %}" class="btn">{% trans "Reset" %}</a>
    </form>
</div>

<p><a href="{% url dashboard:offer-metadata %}" class="btn-large btn-primary">{% trans "Create new offer" %}</a></p>

	<div class="sub-header">
		<h2>{{ queryset_description }}</h2>
	</div>
	{% if offers.count %}
		<form action="." method="post" class="order_table">
			{% csrf_token %}
			<table class="table table-striped table-bordered">
				<tr>
					<th>{% trans "Offer name" %}</th>
					<th>{% trans "Status" %}</th>
					<th>{% trans "Start date" %}</th>
					<th>{% trans "End date" %}</th>
					<th>{% trans "Condition" %}</th>
					<th>{% trans "Benefit" %}</th>
					<th>{% trans "Date created" %}</th>
					<th></th>
				</tr>
				{% for offer in offers %}
				<tr>
					<td><a href="{{ offer.get_absolute_url }}">{{ offer.name }}</a></td>
					<td>{% if offer.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}</td>
					<td>{{ offer.start_date }}</td>
					<td>{{ offer.end_date }}</td>
					<td>{{ offer.condition.description }}</td>
					<td>{{ offer.benefit.description }}</td>
					<td>{{ offer.date_created }}</td>
					<td>
						<a class="btn btn-info" href="{% url dashboard:offer-detail offer.pk %}">{% trans "Stats" %}</a>
						<a class="btn btn-primary" href="{% url dashboard:offer-metadata offer.pk %}">{% trans "Edit" %}</a>
						<a class="btn btn-danger" href="{% url dashboard:offer-delete offer.pk %}">{% trans "Delete" %}</a>
					</td>
				</tr>
				{% endfor %}
			</table>
			{% if page_obj %}
				{% include "catalogue/partials/pagination.html" %}
			{% endif %}
		</form>
	{% else %}
	<p>{% trans "No offers found." %}</p>
	{% endif %}
{% endblock dashboard_content %}
