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

{% block title %}
{% blocktrans %}Products in range '{{ range.name }}'{% endblocktrans %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
	<a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
    <li>
	<a href="{% url dashboard:range-list %}">{% trans "Ranges" %}</a>
        <span class="divider">/</span>
    </li>
    <li>
	<a href="{% url dashboard:range-update range.id %}">'{{ range.name }}'</a>
        <span class="divider">/</span>
    </li>
	<li class="active"><a href=".">{% trans "Products" %}</a></li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header">
	<h1>{% blocktrans %}Products in range {{ range.name }}{% endblocktrans %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}

	<div class="well well-info">
		<div class="sub-header">
			<h3>{% trans "Add products" %}</h3>
		</div>
		<form action="." method="post" class="" enctype="multipart/form-data">
			{% csrf_token %}
			<input type="hidden" name="action" value="add_products"/>
			{% include 'partials/form_fields.html' with form=form %}
			<button type="submit" class="btn btn-primary">{% trans "Go!" %}</button>
		</form>
		{% with uploads=range.file_uploads.all %}
			{% if uploads %}
			<div class="sub-header">
				<h3>{% trans "Upload history" %}</h3>
			</div>
			<table class="table">
				<thead>
				<tr>
					<th>{% trans "Filename" %}</th>
					<th>{% trans "New products" %}</th>
					<th>{% trans "Duplicate products" %}</th>
					<th>{% trans "Unknown products" %}</th>
					<th>{% trans "Date uploaded" %}</th>
				</tr>
				</thead>
				<tbody>
				{% for upload in uploads %}
				<tr>
					<td>{{ upload.filename }}</td>
					<td>{{ upload.num_new_skus }}</td>
					<td>{{ upload.num_duplicate_skus }}</td>
					<td>{{ upload.num_unknown_skus }}</td>
					<td>{{ upload.date_uploaded }}</td>
				</tr>
				{% endfor %}
				</tbody>
			</table>
			{% endif %}
		{% endwith %}
	</div>

	{% if products.count %}
		<form action="." method="post">
			{% csrf_token %}
			<table class="table table-striped table-bordered">
				<tr>
					<th></th>
					<th>{% trans "UPC" %}</th>
					<th>{% trans "Title" %}</th>
					<th>{% trans "Partner" %}</th>
					<th>{% trans "Partner SKU" %}</th>
					<th>{% trans "Price" %}</th>
					<th>{% trans "Is product discountable?" %}</th>
					<th></th>
				</tr>
				{% for product in products %}
				<tr>
					<td>
						<input type="checkbox" name="selected_product" value="{{ product.id }}" />
					</td>
					<td>{{ product.upc|default:"-" }}</td>
					<td>{{ product.get_title }}</td>
					<td>{{ product.stockrecord.partner.name }}</td>
					<td>{{ product.stockrecord.partner_sku }}</td>
					<td>{{ product.stockrecord.price_incl_tax|currency }}</td>
					<td>{% if product.is_discountable %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}</td>
					<td>
						<a class="btn btn-danger" href="#" data-behaviours="remove">{% trans "Remove" %}</a>
					</td>
				</tr>
				{% endfor %}
			</table>

			<div class="well well-danger">
				<input type="hidden" name="action" value="remove_selected_products" />
				<button type="submit" class="btn btn-danger">{% trans "Remove selected products" %}</button>
			</div>

			{% if page_obj %}
				{% include "catalogue/partials/pagination.html" %}
			{% endif %}
		</form>
	{% else %}
	<p>{% trans "No products found." %}</p>
	{% endif %}

	<div class="well well-info">
		<a href="{% url dashboard:range-update range.id %}" class="btn btn-large btn-primary">{% trans "Edit range" %}</a> {% trans "or" %}
		<a href="{% url dashboard:range-list %}" class="">{% trans "return to range list" %}</a>
	</div>
			
{% endblock dashboard_content %}

{% block onbodyload %}
{{ block.super }}
oscar.dashboard.ranges.init()
{% endblock %}
