{% extends '@CpCreationVitiCore/admin/base.html.twig' %}

{% block content %}
    <h1 class="page-header">
        {{ 'marketing.review.moderation.detail_title'|trans({'%product%': review.product.fullName}) }}
    </h1>

    <div class="panel panel-default">
        <div class="panel-heading">
            <a class="btn btn-default" href="{{ path('admin_marketing_product_reviews') }}">
                {{ 'marketing.review.moderation.back_to_list'|trans }}
            </a>
        </div>
    </div>

    <div class="panel panel-info">
        <div class="panel-heading">
            <strong>{{ review.product.fullName }}</strong>
        </div>
        <div class="panel-body">
            <dl class="dl-horizontal">
                <dt>{{ 'marketing.review.field.author'|trans }}</dt>
                <dd>{{ review.authorDisplayName }}</dd>
                <dt>{{ 'marketing.review.field.rating'|trans }}</dt>
                <dd>{{ review.rating }}/5</dd>
                <dt>{{ 'marketing.review.field.status'|trans }}</dt>
                <dd>{{ ('marketing.review.status.' ~ review.status)|trans }}</dd>
                <dt>{{ 'marketing.review.field.date'|trans }}</dt>
                <dd>{{ review.submittedAt|date('d/m/Y H:i') }}</dd>
                {% if review.title %}
                    <dt>{{ 'marketing.review.form.title'|trans }}</dt>
                    <dd><strong>{{ review.title }}</strong></dd>
                {% endif %}
                <dt>{{ 'marketing.review.field.comment'|trans }}</dt>
                <dd>{{ review.comment|nl2br }}</dd>
            </dl>
        </div>
    </div>

    <div class="alert alert-warning">
        <strong>{{ 'marketing.review.moderation.neutrality_title'|trans }}</strong>
        {{ 'marketing.review.moderation.neutrality_notice'|trans }}
    </div>

    {% if is_granted('ROLE_SUPER_ADMIN') %}
        {% if review.status in [
            constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReview::STATUS_PENDING'),
            constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReview::STATUS_REJECTED')
        ] %}
            <div id="review-publish" class="panel {{ intent == 'publish' ? 'panel-success' : 'panel-default' }}">
                <div class="panel-heading">
                    <strong>{{ 'marketing.review.moderation.publish'|trans }}</strong>
                </div>
                <div class="panel-body">
                    <p>{{ 'marketing.review.moderation.publish_confirmation'|trans }}</p>
                    <form method="post" action="{{ path('admin_marketing_product_review_publish', {id: review.id, return: 'detail'}) }}">
                        <input type="hidden" name="_token" value="{{ csrf_token('publish-review-' ~ review.id) }}">
                        <button class="btn btn-success" type="submit">
                            {{ 'marketing.review.moderation.publish'|trans }}
                        </button>
                    </form>
                </div>
            </div>
        {% endif %}

        {% if review.status == constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReview::STATUS_PENDING') %}
            <div id="review-reject" class="panel {{ intent == 'reject' ? 'panel-danger' : 'panel-default' }}">
                <div class="panel-heading">
                    <strong>{{ 'marketing.review.moderation.reject'|trans }}</strong>
                </div>
                <div class="panel-body">
                    <form method="post" action="{{ path('admin_marketing_product_review_reject', {id: review.id, return: 'detail'}) }}">
                        <input type="hidden" name="_token" value="{{ csrf_token('reject-review-' ~ review.id) }}">
                        <div class="form-group">
                            <label for="review-rejection-reason">
                                {{ 'marketing.review.moderation.rejection_reason'|trans }}
                            </label>
                            <select id="review-rejection-reason" class="form-control" name="reason_code" required>
                                <option value="">{{ 'marketing.review.moderation.reason_placeholder'|trans }}</option>
                                {% for reason_code in moderation_reason_codes %}
                                    <option value="{{ reason_code }}">
                                        {{ ('marketing.review.moderation.reason.' ~ reason_code)|trans }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group">
                            <textarea
                                class="form-control"
                                name="reason_detail"
                                maxlength="2000"
                                placeholder="{{ 'marketing.review.moderation.reason_detail_placeholder'|trans }}"
                            ></textarea>
                        </div>
                        <button class="btn btn-danger" type="submit">
                            {{ 'marketing.review.moderation.reject'|trans }}
                        </button>
                    </form>
                </div>
            </div>
        {% endif %}
    {% else %}
        <div class="alert alert-info">
            {{ 'marketing.review.moderation.action_requires_super_admin'|trans }}
        </div>
    {% endif %}
{% endblock %}
