{% extends 'oscar/dashboard/layout.html' %}
{% load i18n %}
{% block title %}
    {% trans "Ranges" %} | {{ 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 "Ranges" %}
            </li>
        </ol>
    </nav>
{% endblock %}
{% block header %}
    <div class="page-header">
        <a href="{% url 'dashboard:range-create' %}" class="btn btn-primary float-right">
            <i class="fas fa-plus-circle"></i>
            {% trans "Create new range" %}
        </a>
        <h1>{% trans "Ranges" %}</h1>
    </div>
{% endblock header %}
{% block dashboard_content %}
    <table class="table table-striped table-bordered">
        <caption>
        <i class="fas fa-ellipsis-h"></i>
        {% trans "Ranges" %}
        </caption>
        {% if ranges %}
            <thead>
                <tr>
                    <th>{% trans "Name" %}</th>
                    <th>{% trans "Num products" %}</th>
                    <th>{% trans "Is public?" %}</th>
                    <th>{% trans "Date created" %}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for range in ranges %}
                    <tr>
                        <td>
                            {% if range.is_editable %}
                                <a href="{% url 'dashboard:range-update' pk=range.id %}">
                                    {{ range.name }}
                                </a>
                            {% else %}
                                {{ range.name }}
                            {% endif %}
                        </td>
                        {% if range.includes_all_products %}
                            <td>{% trans 'All' %}</td>
                        {% else %}
                            <td>{{ range.num_products|default:"-" }}</td>
                        {% endif %}
                        {% if range.is_public %}
                            <td>{% trans "Yes" %}</td>
                        {% else %}
                            <td>{% trans "No" %}</td>
                        {% endif %}
                        <td>{{ range.date_created }}</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">
                                        {% if range.is_editable %}
                                            <a class="dropdown-item"
                                               href="{% url 'dashboard:range-update' pk=range.id %}">
                                                {% trans "Edit" %}
                                            </a>
                                            {% if not range.includes_all_products %}
                                                <a class="dropdown-item"
                                                   href="{% url 'dashboard:range-products' pk=range.id %}">
                                                    {% trans "Edit products" %}
                                                </a>
                                            {% endif %}
                                        {% endif %}
                                        {% if range.is_public %}
                                            <a class="dropdown-item" href="{{ range.get_absolute_url }}">
                                                {% trans "View on site" %}
                                            </a>
                                        {% endif %}
                                        <a class="dropdown-item" href="{% url 'dashboard:range-delete' pk=range.id %}">
                                            {% trans "Delete" %}
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        {% else %}
            <tr>
                <td>{% trans "No ranges found." %}</td>
            </tr>
        {% endif %}
    </table>
    {% include "oscar/dashboard/partials/pagination.html" %}
{% endblock dashboard_content %}
