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

{% load i18n %}

{% block body_class %}{{ block.super }} catalogue{% endblock %}

{% block title %}
{% trans "Stock alerts" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a></li>
            <li class="breadcrumb-item active" aria-current="page">{% trans "Stock alerts" %}</li>
        </ol>
    </nav>
{% endblock %}

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

{% block dashboard_content %}
<div class="table-header">
    <h2 class="float-left"><i class="fas fa-sitemap"></i> {{ description }}</h2>

    <div class="float-right">
        <div class="dropdown">
            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                {% trans "Filter" %}
            </button>
            <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
                <a class="dropdown-item" href="{% url 'dashboard:stock-alert-list' %}">{% trans "All" %}</a>
                <a class="dropdown-item" href="{% url 'dashboard:stock-alert-list' %}?status=Open">{% trans "Open" %}</a>
                <a class="dropdown-item" href="{% url 'dashboard:stock-alert-list' %}?status=Closed">{% trans "Closed" %}</a>
            </div>
        </div>
    </div>
</div>

<table class="table table-striped table-bordered table-hover">
    {% if alerts %}
    <tr>
        <th>{% trans "Product" %}</th>
        <th>{% trans "Partner" %}</th>
        <th>{% trans "Low stock threshold" %}</th>
        <th>{% trans "Current available stock" %}</th>
        <th>{% trans "Date alert raised" %}</th>
        <th>{% trans "Status" %}</th>
        <th></th>
    </tr>
    {% for alert in alerts %}
    <tr>
        <td>
            <a href="{% url 'dashboard:catalogue-product' alert.stockrecord.product.id %}{% if request.GET.urlencode %}?{{ request.GET.urlencode }}{% endif %}">
                {{ alert.stockrecord.product.get_title }}
            </a>
        </td>
        <td>{{ alert.stockrecord.partner.display_name }}</td>
        <td>{{ alert.stockrecord.low_stock_threshold }}</td>
        <td>{{ alert.stockrecord.net_stock_level }}</td>
        <td>{{ alert.date_created }}</td>
        <td>{{ alert.status }}</td>
        <td>
            <a class="btn btn-info" href="{% url 'dashboard:catalogue-product' pk=alert.stockrecord.product.id %}">{% trans "Update" %}</a>
        </td>
    </tr>
    {% endfor %}

    {% else %}

    <tr><td>{% trans "No stock alerts found." %}</td></tr>

    {% endif %}
</table>
{% include "oscar/dashboard/partials/pagination.html" %}

{% endblock dashboard_content %}
