{% extends 'dashboard.html' %}
{% load static %}

{% block head_title %}Product Stock | {% endblock %}

{% block content %}
<article>
    <header class="object-header">
        <h1><img src="{% static 'images/warehouse.png' %}"> Stock</h1>
        <p><strong>Total in warehouse</strong> = available stock + unfulfilled</p>
    </header>

    <section class="panel">
        <table>
            <thead>
                <tr>
                    <th colspan="2">Product</th>
                    <th>SKU</th>
                    <th>Available Stock</th>
                    <th>Total in warehouse</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
            {% for variant in variant_list %}
                <tr>
                {% with product=variant.product %}
                    <td>
                        <figure class="product-figure">
                            {% if variant.image %}
                            <img src="{{variant.image.image.url}}" alt="{{variant.image.image}}">
                            {% else %}
                            <img src="{{product.get_first_img.image.url}}" alt="{{product.get_first_img.image}}">
                            {% endif %}
                        </figure>
                    </td>
                    <td><strong>{{ variant }}</strong></td>
                    <td>{{ variant.sku }}</td>
                    <td>{{ variant.stock|default_if_none:"0" }}</td>
                    <td>{{ variant.total_in_warehouse }}</td>
                    <td>
                        <a href="{% url 'dashboard:variant-restock' product.pk variant.pk %}" class="btn">Restock &rarr;</a> 
                    </td>
                {% endwith %}
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </section>
</article>
{% endblock %}
