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

{% block body_class %}{{ block.super }} reviews{% endblock %}
{% block title %}
    {% trans "Reviews" %} | {{ 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 "Reviews" %}</li>
        </ol>
    </nav>
{% endblock %}

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

{% block dashboard_content %}

    <div class="table-header">
        <h3><i class="fas fa-search"></i> {% trans "Review Search" %}</h3>
    </div>
    <div class="card card-body">
        <form method="get" class="form-inline">
            {% include 'oscar/dashboard/partials/form_fields_inline.html' with form=form %}
            <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Searching...' %}">{% trans "Search" %}</button>
        </form>
    </div>

    {% if review_list %}

        <form method="post">
            {% csrf_token %}
            <table class="table table-striped table-bordered table-hover">
                <caption>
                    <h3 class="float-left"><i class="fas fa-thumbs-up"></i> {{ description }}</h3>
                    <div class="float-right">
                        <div class="form-inline">
                            {% trans "Update status of selected reviews" %}
                            {{ review_form.status }}
                            <input type="hidden" name="action" value="update_selected_review_status" />
                            <button type="submit" name="update" class="btn btn-success" data-loading-text="{% trans 'Updating...' %}">{% trans "Update" %}</button>
                        </div>
                    </div>
                </caption>
                <tr>
                    <th></th>
                    <th>{% trans "Title" context "Review title" %}</th>
                    <th>{% trans "Product" %}</th>
                    <th>{% trans "User" %}</th>
                    <th>{% anchor 'score' _("Score") %}</th>
                    <th>{% anchor 'total_votes' _("Votes") %}</th>
                    <th>{% trans "Status" %}</th>
                    <th>{% anchor 'date_created' _("Date created") %}</th>
                    <th></th>
                </tr>
                {% for review in review_list %}
                    <tr>
                        <td><input type="checkbox" name="selected_review" class="selected_review" value="{{ review.id }}"/></td>
                        <td>
                            <a href="{% url 'dashboard:reviews-update' pk=review.id %}">{{ review.title }}</a>
                        </td>
                        <td>
                            {% if review.product %}
                                <a href='{{ review.product.get_absolute_url }}'>{{ review.product.title }}</a>
                            {% else %}
                                {% trans "[Product deleted]" %}
                            {% endif %}
                        </td>
                        <td>
                            {% if not review.is_anonymous %}
                                <a href="{% url 'dashboard:user-detail' pk=review.user.id %}">{{ review.reviewer_name }}</a>
                            {% else %}
                                {{ review.name }}
                            {% endif %}
                        </td>
                        <td>
                            {{ review.score|floatformat:1 }} / {{ 5.0|floatformat:1 }}
                        </td>
                        <td>{{ review.total_votes }}</td>
                        <td>
                            {% if review.status == 1 %}
                                <span class="badge badge-success">
                            {% elif review.status == 2 %}
                                <span class="badge badge-danger">
                            {% else %}
                                <span class="badge badge-info">
                            {% endif %}
                                {{ review.get_status_display }}
                            </span>
                        </td>
                        <td>{{ review.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 review.title and review.product %}
                                            <a class="dropdown-item" href="{% url 'catalogue:reviews-detail' product_slug=review.product.slug product_pk=review.product.id pk=review.id %}">
                                                {% trans "View on site" %}
                                            </a>
                                        {% endif %}
                                        <a class="dropdown-item" href="{% url 'dashboard:reviews-update' pk=review.id %}">{% trans "Edit" %}</a>
                                        <a class="dropdown-item" href="{% url 'dashboard:reviews-delete' pk=review.id %}">{% trans "Delete" %}</a>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </table>
            {% include "oscar/dashboard/partials/pagination.html" %}
        </form>
    {% else %}
        <table class="table table-striped table-bordered table-hover">
            <caption>{{ description }}</caption>
            <tr><td>{% trans "No reviews found." %}</td></tr>
        </table>
    {% endif %}

{% endblock dashboard_content %}
