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

{% block content %}
    <h1 class="page-header">{{ 'marketing.review_report.admin.title'|trans }}</h1>

    <div class="panel panel-default">
        <div class="panel-heading">
            <a class="btn btn-danger btn-rounded" href="{{ path('admin_marketing') }}">
                {{ 'marketing.common.back'|trans }}
            </a>
        </div>
    </div>

    <div class="panel panel-info">
        <div class="panel-heading">{{ 'marketing.review_report.admin.latest'|trans }}</div>
        <div class="panel-body">
            {% if reports is empty %}
                <p class="text-muted">{{ 'marketing.review_report.admin.empty'|trans }}</p>
            {% else %}
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>{{ 'marketing.review_report.field.date'|trans }}</th>
                                <th>{{ 'marketing.review_report.field.review'|trans }}</th>
                                <th>{{ 'marketing.review_report.field.reason'|trans }}</th>
                                <th>{{ 'marketing.review_report.field.status'|trans }}</th>
                                <th>{{ 'marketing.review_report.field.actions'|trans }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for report in reports %}
                                <tr>
                                    <td>{{ report.reportedAt|date('d/m/Y H:i') }}</td>
                                    <td>
                                        <strong>{{ report.review.product.fullName }}</strong><br>
                                        {{ report.review.authorDisplayName }} — {{ report.review.rating }}/5<br>
                                        {% if report.review.title %}<strong>{{ report.review.title }}</strong><br>{% endif %}
                                        {{ report.review.comment }}
                                    </td>
                                    <td>
                                        {{ ('marketing.review_report.reason.' ~ report.reason)|trans }}
                                        {% if report.comment %}
                                            <div class="text-muted">{{ report.comment }}</div>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {{ ('marketing.review_report.status.' ~ report.status)|trans }}
                                        {% if report.resolutionNote %}
                                            <div class="text-muted">{{ report.resolutionNote }}</div>
                                        {% endif %}
                                        {% if report.resolvedAt %}
                                            <div class="text-muted">{{ report.resolvedAt|date('d/m/Y H:i') }}</div>
                                        {% endif %}
                                    </td>
                                    <td style="min-width: 240px;">
                                        {% if report.status == constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReviewReport::STATUS_OPEN') and is_granted('ROLE_SUPER_ADMIN') %}
                                            <form method="post" action="{{ path('admin_marketing_product_review_report_resolve', {id: report.id}) }}" style="margin-bottom: 8px;">
                                                <input type="hidden" name="_token" value="{{ csrf_token('resolve-review-report-' ~ report.id) }}">
                                                <input class="form-control input-sm" type="text" name="note" maxlength="2000" placeholder="{{ 'marketing.review_report.admin.note_placeholder'|trans }}">
                                                <button class="btn btn-success btn-sm" type="submit" style="margin-top: 5px;">
                                                    {{ 'marketing.review_report.admin.resolve'|trans }}
                                                </button>
                                            </form>
                                            <form method="post" action="{{ path('admin_marketing_product_review_report_dismiss', {id: report.id}) }}">
                                                <input type="hidden" name="_token" value="{{ csrf_token('dismiss-review-report-' ~ report.id) }}">
                                                <button class="btn btn-default btn-sm" type="submit">
                                                    {{ 'marketing.review_report.admin.dismiss'|trans }}
                                                </button>
                                            </form>
                                            {% if report.review.status == constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReview::STATUS_PUBLISHED') %}
                                                <form method="post" action="{{ path('admin_marketing_product_review_report_withdraw', {id: report.id}) }}" style="margin-top: 8px;">
                                                    <input type="hidden" name="_token" value="{{ csrf_token('withdraw-review-report-' ~ report.id) }}">
                                                    <select class="form-control input-sm" name="reason_code" required>
                                                        <option value="">{{ 'marketing.review_report.admin.withdrawal_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>
                                                    <textarea class="form-control input-sm" name="note" maxlength="2000" placeholder="{{ 'marketing.review.moderation.reason_detail_placeholder'|trans }}" style="margin-top: 5px;"></textarea>
                                                    <button class="btn btn-danger btn-sm" type="submit" style="margin-top: 5px;">
                                                        {{ 'marketing.review_report.admin.withdraw_review'|trans }}
                                                    </button>
                                                </form>
                                            {% endif %}
                                        {% elseif report.status == constant('CpCreation\\VitiCore\\Marketing\\Model\\ProductReviewReport::STATUS_OPEN') %}
                                            <span class="text-muted">{{ 'marketing.review_report.admin.super_admin_decision'|trans }}</span>
                                        {% else %}
                                            <span class="text-muted">{{ 'marketing.review_report.admin.processed'|trans }}</span>
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="text-center">
                    {{ knp_pagination_render(reports) }}
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
