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

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

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

    <div class="panel panel-default">
        <div class="panel-heading">
            <strong>{{ 'marketing.abandoned_cart.reminder.filters.title'|trans }}</strong>
        </div>
        <div class="panel-body">
            <form method="get" action="{{ path('admin_marketing_abandoned_cart_reminders') }}">
                <div class="row">
                    <div class="col-md-5">
                        <label for="abandoned-cart-reminder-filter-search">
                            {{ 'marketing.abandoned_cart.reminder.filters.search'|trans }}
                        </label>
                        <input
                            id="abandoned-cart-reminder-filter-search"
                            class="form-control"
                            type="search"
                            name="search"
                            value="{{ filters.search }}"
                            maxlength="200"
                            placeholder="{{ 'marketing.abandoned_cart.reminder.filters.search_placeholder'|trans }}"
                        >
                    </div>
                    <div class="col-md-3">
                        <label for="abandoned-cart-reminder-filter-status">
                            {{ 'marketing.abandoned_cart.reminder.filters.status'|trans }}
                        </label>
                        <select id="abandoned-cart-reminder-filter-status" class="form-control" name="status">
                            <option value="">{{ 'marketing.abandoned_cart.reminder.filters.all_statuses'|trans }}</option>
                            {% for status in statuses %}
                                <option value="{{ status }}" {{ filters.status == status ? 'selected' }}>
                                    {{ ('marketing.abandoned_cart.reminder.status.' ~ status)|trans }}
                                </option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label for="abandoned-cart-reminder-filter-rule">
                            {{ 'marketing.abandoned_cart.reminder.filters.rule'|trans }}
                        </label>
                        <select id="abandoned-cart-reminder-filter-rule" class="form-control" name="rule">
                            <option value="">{{ 'marketing.abandoned_cart.reminder.filters.all_rules'|trans }}</option>
                            {% for rule in rules %}
                                <option value="{{ rule.id }}" {{ filters.rule == rule.id.toString ? 'selected' }}>
                                    {{ rule.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div style="margin-top: 15px;">
                    <button class="btn btn-primary" type="submit">
                        {{ 'marketing.abandoned_cart.reminder.filters.apply'|trans }}
                    </button>
                    {% if has_filters %}
                        <a class="btn btn-default" href="{{ path('admin_marketing_abandoned_cart_reminders') }}">
                            {{ 'marketing.abandoned_cart.reminder.filters.reset'|trans }}
                        </a>
                    {% endif %}
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-info">
        <div class="panel-heading">
            {{ 'marketing.abandoned_cart.reminder.admin.results'|trans({
                '%count%': reminders.totalItemCount
            }) }}
        </div>
        <div class="panel-body">
            {% if reminders is empty %}
                <p class="text-muted">
                    {{ (has_filters
                        ? 'marketing.abandoned_cart.reminder.filters.no_results'
                        : 'marketing.abandoned_cart.reminder.admin.empty'
                    )|trans }}
                </p>
            {% else %}
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.created_at'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.recipient'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.cart'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.rule'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.coupon'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.status'|trans }}</th>
                                <th>{{ 'marketing.abandoned_cart.reminder.field.tracking'|trans }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for reminder in reminders %}
                                {% set status_class = {
                                    scheduled: 'label-info',
                                    sent: 'label-success',
                                    recovered: 'label-primary',
                                    canceled: 'label-default',
                                    expired: 'label-warning'
                                }[reminder.status] ?? 'label-default' %}
                                <tr>
                                    <td>{{ reminder.scheduledAt|date('d/m/Y H:i') }}</td>
                                    <td>{{ reminder.recipientEmail }}</td>
                                    <td>
                                        <a href="{{ path('admin_order_order', {id: reminder.cart.id}) }}">
                                            {{ reminder.cart.token ?: reminder.cart.id }}
                                        </a>
                                    </td>
                                    <td>{{ reminder.rule.name }}</td>
                                    <td>
                                        {% if reminder.promo %}
                                            <div>{{ reminder.promo.title }}</div>
                                            <div class="text-muted">
                                                {{ 'marketing.abandoned_cart.rule.price_group_value'|trans({
                                                    '%group%': reminder.rule.priceGroup.name
                                                }) }}
                                            </div>
                                        {% else %}
                                            —
                                        {% endif %}
                                    </td>
                                    <td>
                                        <span class="label {{ status_class }}">
                                            {{ ('marketing.abandoned_cart.reminder.status.' ~ reminder.status)|trans }}
                                        </span>
                                    </td>
                                    <td>
                                        {% if reminder.sentAt %}
                                            <div>
                                                {{ 'marketing.abandoned_cart.reminder.tracking.sent_at'|trans }} :
                                                {{ reminder.sentAt|date('d/m/Y H:i') }}
                                            </div>
                                        {% endif %}
                                        {% if reminder.recoveredAt %}
                                            <div>
                                                {{ 'marketing.abandoned_cart.reminder.tracking.recovered_at'|trans }} :
                                                {{ reminder.recoveredAt|date('d/m/Y H:i') }}
                                            </div>
                                        {% endif %}
                                        <div class="text-muted">
                                            {{ 'marketing.abandoned_cart.reminder.tracking.expires_at'|trans }} :
                                            {{ reminder.expiresAt|date('d/m/Y H:i') }}
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="text-center">
                    {{ knp_pagination_render(reminders) }}
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
