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

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            {{ 'withdrawal.admin.list.filters_title'|trans }}
        </div>
        <div class="panel-body">
            <form method="get" action="{{ path('admin_withdrawal') }}">
                <div class="row">
                    <div class="col-md-5">
                        <div class="form-group">
                            <label for="withdrawal-search">{{ 'withdrawal.admin.list.search_label'|trans }}</label>
                            <input
                                type="search"
                                name="search"
                                id="withdrawal-search"
                                class="form-control"
                                value="{{ search }}"
                                placeholder="{{ 'withdrawal.admin.list.search_placeholder'|trans }}"
                            >
                            <p class="help-block">{{ 'withdrawal.admin.list.search_help'|trans }}</p>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label for="withdrawal-status">{{ 'withdrawal.admin.list.status_filter.label'|trans }}</label>
                            <select name="status" id="withdrawal-status" class="form-control">
                                <option value="all" {{ status == 'all' ? 'selected' }}>
                                    {{ 'withdrawal.admin.list.status_filter.all'|trans }}
                                </option>
                                <option value="pending" {{ status == 'pending' ? 'selected' }}>
                                    {{ 'withdrawal.admin.list.status_filter.pending'|trans }}
                                </option>
                                <option value="processed" {{ status == 'processed' ? 'selected' }}>
                                    {{ 'withdrawal.admin.list.status_filter.processed'|trans }}
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <label>&nbsp;</label>
                        <button type="submit" class="btn btn-primary btn-block">
                            {{ 'withdrawal.admin.list.search_submit'|trans }}
                        </button>
                    </div>
                    <div class="col-md-2">
                        <label>&nbsp;</label>
                        <a href="{{ path('admin_withdrawal') }}" class="btn btn-default btn-block">
                            {{ 'withdrawal.admin.list.reset'|trans }}
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            {{ 'withdrawal.admin.list.title'|trans({ '%count%': items|length }) }}
        </div>
        <div class="table-responsive">
            <table class="table table-bordered dataTable" width="100%" cellspacing="0" data-order='[[0, "desc"]]'>
                <thead>
                    <tr>
                        <th>{{ 'withdrawal.admin.list.columns.submitted_at'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.customer'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.email'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.reference'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.reception'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.reason'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.acknowledgement'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.status'|trans }}</th>
                        <th>{{ 'withdrawal.admin.list.columns.actions'|trans }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in items %}
                        <tr>
                            <td data-order="{{ item.submittedAt|date('Y-m-d H:i:s') }}">{{ item.submittedAt|date('d/m/Y H:i:s') }}</td>
                            <td>{{ item.firstname }} {{ item.lastname }}</td>
                            <td><a href="mailto:{{ item.receiptEmail }}">{{ item.receiptEmail }}</a></td>
                            <td>{{ item.contractReference }}</td>
                            <td>
                                {{ (item.orderReceived is same as(true) ? 'withdrawal.form.yes' : (item.orderReceived is same as(false) ? 'withdrawal.form.no' : 'withdrawal.form.not_provided'))|trans }}
                                {% if item.orderReceived and item.receivedAt %}
                                    <br><small>{{ item.receivedAt|date('d/m/Y') }}</small>
                                {% endif %}
                            </td>
                            <td>
                                {{ item.reasonCode ? ('withdrawal.reason.' ~ item.reasonCode)|trans : '—' }}
                                {% if item.comment %}
                                    <br><small><strong>{{ 'withdrawal.summary.comment'|trans }} :</strong> {{ item.comment|u.truncate(160, '…') }}</small>
                                {% endif %}
                            </td>
                            <td>
                                {% if item.acknowledgedAt %}
                                    <span class="label label-success">{{ 'withdrawal.admin.list.acknowledgement_sent'|trans }}</span>
                                    <br><small>{{ item.acknowledgedAt|date('d/m/Y H:i:s') }}</small>
                                {% else %}
                                    <span class="label label-warning">{{ 'withdrawal.admin.list.acknowledgement_pending'|trans }}</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if item.processedAt %}
                                    <span class="label label-success">{{ 'withdrawal.admin.list.processed'|trans }}</span>
                                    <br><small>{{ item.processedAt|date('d/m/Y H:i:s') }}</small>
                                {% else %}
                                    <span class="label label-warning">{{ 'withdrawal.admin.list.pending'|trans }}</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="{{ path('admin_order_order', { id: item.cart.id }) }}" class="btn btn-info btn-sm">
                                    {{ 'withdrawal.admin.list.view_order'|trans }}
                                </a>
                            </td>
                        </tr>
                    {% else %}
                        <tr>
                            <td colspan="9" class="text-center">{{ 'withdrawal.admin.list.empty'|trans }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
