{% load reviews_tags %}
{% load i18n %}
<article class="review">
    <header>
        <h3 class="star-rating {{ review.score|as_stars }}">
            <span>
                <i class="fas fa-star"></i>
                <i class="fas fa-star"></i>
                <i class="fas fa-star"></i>
                <i class="fas fa-star"></i>
                <i class="fas fa-star"></i>
            </span>
            <a href="{{ review.get_absolute_url }}">{{ review.title }}</a>
        </h3>
    </header>
    <p>
        {{ review.body|striptags }}
    </p>
    <p>
        <small>
        {% if review.user == user %}
            {% blocktrans with review_date=review.date_created %}
                Reviewed by you on {{ review_date }}
            {% endblocktrans %}
        {% else %}
            {% blocktrans with name=review.reviewer_name review_date=review.date_created %}
                Reviewed by
                <strong>{{ name }}</strong>
                on {{ review_date }}
            {% endblocktrans %}
        {% endif %}
        |
        <a href="{% url 'catalogue:reviews-detail' product_slug=product.slug product_pk=product.pk pk=review.pk %}">
            {% trans 'Permalink' %}
        </a>
        </small>
    </p>
    {% if review|may_vote:user %}
        <small>
        {% trans "Is this review helpful?" %}
        </small>
        <form action="{% url 'catalogue:reviews-vote' product_slug=product.slug product_pk=product.pk pk=review.pk %}"
              method="post"
              class="vote_agree">
            {% csrf_token %}
            <input type="hidden" name="delta" value="1"/>
            <button type="submit" class="btn btn-success btn-sm" data-loading-text="{% trans 'Submitting...' %}">
                {% trans "Yes" %}
            </button>
        </form>
        <form action="{% url 'catalogue:reviews-vote' product_slug=product.slug product_pk=product.pk pk=review.pk %}"
              method="post">
            {% csrf_token %}
            <input type="hidden" name="delta" value="-1"/>
            <button type="submit" class="btn btn-danger btn-sm" data-loading-text="{% trans 'Submitting...' %}">
                {% trans "No" %}
            </button>
        </form>
    {% endif %}
    <p>
        <small>
        {% if review.has_votes %}
            {% blocktrans with num_up_votes=review.num_up_votes count num_votes=review.total_votes %}
                <strong>{{ num_up_votes }}</strong>
                of {{ num_votes }} customer found this useful
                {% plural %}
                <strong>{{ num_up_votes }}</strong>
                of {{ num_votes }} customers found this useful
            {% endblocktrans %}
        {% else %}
            {% trans "This review has no votes." %}
        {% endif %}
        </small>
    </p>
</article>
