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

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

{% block title %}
    {% trans "Product 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 "Product alerts" %}</li>
        </ol>
    </nav>
{% endblock %}

{% block headertext %}
    {% trans "Product alerts" %}
{% endblock %}

{% block dashboard_content %}
    <div class="table-header">
        <h3><i class="fas fa-search"></i> {% trans "Search product alerts" %}</h3>
    </div>
    <div class="card card-body">
        <form id="search_alert_form" method="get" class="form-inline">
            {% include "oscar/dashboard/partials/form_fields_inline.html" with form=form %}
            <button type="submit" class="btn btn-primary mr-2" data-loading-text="{% trans 'Searching...' %}">{% trans "Search" %}</button>
            {% trans "or" %}
            <a href="{% url 'dashboard:user-alert-list' %}" class="btn btn-secondary ml-2">{% trans "reset" %}</a>
        </form>
    </div>

    <div class="table-header">
        <h2><i class="fas fa-users"></i> {{ queryset_description }}</h2>
    </div>

    {% if alerts %}
        <table class="table table-striped table-bordered table-hover">
            <tr>
                <th>{% trans "Product" %}</th>
                <th>{% trans "User" %}</th>
                <th>{% trans "Status" %}</th>
                <th>{% trans "Date created" %}</th>
                <th>{% trans "Date alert sent" %}</th>
                <th></th>
            </tr>
            {% for alert in alerts %}
                <tr>
                    <td>
                        <a href="{{ alert.product.get_absolute_url }}">{{ alert.product }}</a>
                    </td>
                    <td>
                        {% if alert.user %}
                            <a href="{% url 'dashboard:user-detail' pk=alert.user.id %}">{{ alert.user.email }}</a>
                        {% else %}
                            {{ alert.email }} {% trans "(Anonymous)" %}
                        {% endif %}
                    </td>
                    <td>
                        {{ alert.status }}
                    </td>
                    <td>{{ alert.date_created }}</td>
                    <td>{{ alert.date_closed|default:"-" }}</td>
                    <td>
                        <div class="btn-toolbar">
                            <div class="dropdown">
                                <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    {% trans "Actions" %}
                                </button>
                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
                                    <a class="dropdown-item" href="{% url 'dashboard:user-alert-update' pk=alert.id %}">
                                        {% trans "Edit" %}
                                    </a>
                                    <a class="dropdown-item" href="{% url 'dashboard:user-alert-delete' pk=alert.id %}">
                                        {% trans "Delete" %}
                                    </a>
                                </div>
                            </div>
                        </div>

                    </td>
                </tr>
            {% endfor %}
        </table>

        {% include "oscar/dashboard/partials/pagination.html" %}

    {% else %}
        <table class="table table-striped table-bordered table-hover">
            <tr><td>{% trans "No alerts found." %}</td></tr>
        </table>
    {% endif %}

{% endblock dashboard_content %}
