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

{% block body_class %}create-page{% endblock %}

{% block title %}
{% blocktrans with name=range.name %}Products in 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 "Range management" %}</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">{% trans "Products" %}</li>	  	
</ul>
{% endblock %}

{% block headertext %}
{{ range.name }}: {% trans "products" %}
{% endblock %}

{% block dashboard_content %}
<div class="table-header">
	<h3>{% trans "Add products" %}</h3>
</div>

<div class="well">

	<form action="." method="post" class="form-stacked" enctype="multipart/form-data">
		{% csrf_token %}
		<input type="hidden" name="action" value="add_products"/>
		{% include 'partials/form_fields.html' with form=form %}
        <div class="controls">
            <button type="submit" class="btn btn-primary">{% trans "Go!" %}</button>
        </div>
	</form>

	{% with uploads=range.file_uploads.all %}
		{% if uploads %}
		<div class="table-header">
			<h3>{% trans "Upload history" %}</h3>
		</div>
		<table class="table table-striped table-bordered table-hover">
			<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 %}


	{% if products.count %}
		<form action="." method="post">
			{% csrf_token %}
			<table class="table table-striped table-bordered table-hover">
                <caption>
                    <h3 class="pull-left">{% trans "Products in Range" %}</h3>
                    <div class="pull-right">
        				<input type="hidden" name="action" value="remove_selected_products" />
        				<button type="submit" class="btn">{% trans "Remove selected products" %}</button>
        			</div>
                </caption>
				<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.display_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>

			{% include "partials/pagination.html" %}
		</form>

	{% else %}
	<table class="table table-striped table-bordered table-hover">
        <caption>
            {% trans "Products in Range" %}
        </caption>
	    <tr><td>{% trans "No products found." %}</td></tr>
	</table>
	{% endif %}

	<div class="form-actions">
		<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>

</div>

{% endblock dashboard_content %}

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