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

{% block body_class %}reviews{% endblock %}
{% block title %}
{% trans "Reviews" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
	<a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
	<li class="active"><a href=".">{% trans "Reviews" %}</a></li>
</ul>
{% endblock %}

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

{% block dashboard_content %}

<div class="well well-info">
	<div class="sub-header"><h3>{% trans "Review Search" %}</h3></div>
    <form action="." method="get" class="form-inline">
        {% include 'partials/form_fields_inline.html' with form=form %}
		<button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
    </form>
</div>

<h2>{{ description }}</h2>

{% if review_list|length %}
<form action="." method="post">
    {% csrf_token %}
    <table class="table table-striped table-bordered">
        <tr>
            <th></th>
			<th>{% trans "Review Title" %}</th>
			<th>{% trans "Review For Product" %}</th>
			<th>{% trans "User" %}</th>
			<th>{% trans "Score" %}</th>
			<th>{% trans "Votes" %}</th>
			<th>{% trans "Status" %}</th>
			<th>{% trans "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>
					{% if review.product %}
						<a href="{% url catalogue:reviews-detail review.product.slug review.product.id review.id %}">{{ review.title }}</a>
					{% else %}
						{{ review.title }}
					{% endif %}
                </td>
            <td>
				{% if review.product %}
					<a href='{% url catalogue:detail review.product.slug review.product.id %}'>{{ review.product.title }}</a> </td>
				{% else %}
					[Product deleted]
				{% endif %}
            <td>
				{% if review.user %}
                <a href="{% url dashboard:user-detail review.user.id %}">{{ review.get_reviewer_name }}</a>
				{% else %}
				{{ review.name }}
				{% endif %}
            </td>
            <td>
                {{ review.score|floatformat:1 }} / 5.0
            </td>
            <td>{{ review.total_votes }}</td>
            <td>
            {% if review.status == 1 %}
                <span class="label label-success">
            {% elif review.status == 2 %}
                <span class="label label-important">
            {% else %}
                <span class="label label-info">
            {% endif %}
                    {{ review.get_status_display }}
                </span>
            </td>
            <td>{{ review.date_created }}</td>
            <td>
				<a class="btn btn-success" href="{% url dashboard:reviews-update review.id %}">{% trans "Edit" %}</a>
				<a class="btn btn-danger" href="{% url dashboard:reviews-delete review.id %}">{% trans "Delete" %}</a>
            </td>
        </tr>
        {% endfor %}
    </table>

    <div class="well well-danger">
		{% trans "Update status of selected reviews" %}
        {{ review_form.status }}
	<input type="hidden" name="action" value="update_selected_review_status" />
	<button type="submit" class="btn btn-success">{% trans "Update" %}</button>
    </div>

{% if page_obj %}
    {% include "catalogue/partials/pagination.html" %}
{% endif %}

</form>

{% else %}

<p>{% trans "No reviews found." %}</p>

{% endif %}

{% endblock dashboard_content %}
