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

{% block content %}
    <div class="row">
        <div class="col-md-3">
            <div class="panel panel-primary">
                <div class="panel-heading">{{ 'admin_client_import.dashboard.total'|trans }}</div>
                <div class="panel-body"><strong class="h3">{{ statistics.total }}</strong></div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="panel panel-success">
                <div class="panel-heading">{{ 'admin_client_import.dashboard.enabled'|trans }}</div>
                <div class="panel-body"><strong class="h3">{{ statistics.enabled }}</strong></div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="panel panel-warning">
                <div class="panel-heading">{{ 'admin_client_import.dashboard.disabled'|trans }}</div>
                <div class="panel-body"><strong class="h3">{{ statistics.disabled }}</strong></div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="panel panel-info">
                <div class="panel-heading">{{ 'admin_client_import.dashboard.last_import'|trans }}</div>
                <div class="panel-body">
                    {% if latest_import %}
                        <strong>{{ latest_import.createdAt|date('d-m-Y H:i') }}</strong><br>
                        <small>{{ latest_import.originalFilename }}</small>
                    {% else %}
                        {{ 'admin_client_import.dashboard.no_import'|trans }}
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">
            {{ 'admin_client_import.base.title'|trans }} ({{ items|length }})
            <div class="pull-right">
                <a href="{{ path('admin_imported_client_import') }}" class="btn btn-default btn-xs">
                    {{ 'admin_client_import.action'|trans }}
                </a>
            </div>
        </div>
        <div class="panel-body">
            <p>{{ 'admin_client_import.base.help'|trans }}</p>
            <form method="get" action="{{ path('admin_imported_client') }}" class="form-inline">
                <div class="form-group">
                    <label for="imported_client_search">{{ 'admin_client_import.base.search'|trans }}</label>
                    <input
                        type="search"
                        id="imported_client_search"
                        name="search"
                        class="form-control"
                        value="{{ search }}"
                        placeholder="{{ 'admin_client_import.base.search_placeholder'|trans }}"
                    >
                </div>
                <button type="submit" class="btn btn-primary">{{ 'admin_client_import.base.search_submit'|trans }}</button>
                {% if search %}
                    <a href="{{ path('admin_imported_client') }}" class="btn btn-default">
                        {{ 'admin_client_import.base.search_reset'|trans }}
                    </a>
                {% endif %}
            </form>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered dataTable" width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th>#</th>
                    <th>{{ 'admin_client_import.base.email'|trans }}</th>
                    <th>{{ 'admin_client_import.base.group'|trans }}</th>
                    <th>{{ 'admin_client_import.base.application_status'|trans }}</th>
                    <th>{{ 'admin_client_import.base.updated_at'|trans }}</th>
                    <th>{{ 'admin_client_import.base.actions'|trans }}</th>
                </tr>
                </thead>
                <tbody>
                {% for item in items %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ item.email }}</td>
                        <td>{{ item.group.name }}</td>
                        <td>
                            {% if item.shouldApplyOnRegistration %}
                                <span class="label label-success">{{ 'admin_client_import.base.applied'|trans }}</span>
                            {% else %}
                                <span class="label label-default">{{ 'admin_client_import.base.not_applied'|trans }}</span>
                            {% endif %}
                        </td>
                        <td>{{ item.updatedAt|date('d-m-Y H:i:s') }}</td>
                        <td>
                            <a href="{{ path('admin_imported_client_show', {id: item.id}) }}" class="btn btn-info btn-sm">
                                <i class="fas fa-search"></i> {{ 'admin_client_import.base.details'|trans }}
                            </a>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="6" class="text-center">{{ 'admin_client_import.base.empty'|trans }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">{{ 'admin_client_import.dashboard.distribution_title'|trans }}</div>
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>{{ 'admin_client_import.base.group'|trans }}</th>
                    <th>{{ 'admin_client_import.dashboard.total'|trans }}</th>
                    <th>{{ 'admin_client_import.dashboard.enabled'|trans }}</th>
                    <th>{{ 'admin_client_import.dashboard.disabled'|trans }}</th>
                </tr>
                </thead>
                <tbody>
                {% for group in group_distribution %}
                    <tr>
                        <td>{{ group.group_name }}</td>
                        <td>{{ group.total }}</td>
                        <td>{{ group.enabled }}</td>
                        <td>{{ group.disabled }}</td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="4" class="text-center">{{ 'admin_client_import.dashboard.no_distribution'|trans }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">{{ 'admin_client_import.history.title'|trans }}</div>
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>{{ 'admin_client_import.history.date'|trans }}</th>
                    <th>{{ 'admin_client_import.history.filename'|trans }}</th>
                    <th>{{ 'admin_client_import.analysis.total_rows'|trans }}</th>
                    <th>{{ 'admin_client_import.history.created'|trans }}</th>
                    <th>{{ 'admin_client_import.history.updated'|trans }}</th>
                    <th>{{ 'admin_client_import.base.actions'|trans }}</th>
                </tr>
                </thead>
                <tbody>
                {% for import in recent_imports %}
                    <tr>
                        <td>{{ import.createdAt|date('d-m-Y H:i:s') }}</td>
                        <td>{{ import.originalFilename }}</td>
                        <td>{{ import.totalRows }}</td>
                        <td>{{ import.createdCount }}</td>
                        <td>{{ import.updatedCount }}</td>
                        <td>
                            <a href="{{ path('admin_imported_client_import_show', {id: import.id}) }}" class="btn btn-info btn-sm">
                                <i class="fas fa-search"></i> {{ 'admin_client_import.base.details'|trans }}
                            </a>
                            <a href="{{ path('admin_imported_client_import_download', {id: import.id}) }}" class="btn btn-default btn-sm">
                                <i class="fas fa-download"></i> {{ 'admin_client_import.history.download'|trans }}
                            </a>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="6" class="text-center">{{ 'admin_client_import.history.empty'|trans }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
