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

{% block content %}
    <h1 class="page-header">Tableau de bord</h1>

    {% if is_granted('ROLE_ORDER') or is_granted('ROLE_MARKETING') or is_granted('ROLE_ADMIN') %}
        {% set todo = todoCounts|default({
            withdrawals: 0,
            reviews: 0,
            offlinePayments: 0,
            deliveries: 0
        }) %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>{{ 'admin.homepage.todo.title'|trans }}</strong>
                <span class="text-muted">— {{ 'admin.homepage.todo.subtitle'|trans }}</span>
            </div>
            <div class="table-responsive">
                <table class="table table-hover" style="margin-bottom: 0;">
                    <thead>
                        <tr>
                            <th scope="col">{{ 'admin.homepage.todo.columns.task'|trans }}</th>
                            <th scope="col" class="text-center">{{ 'admin.homepage.todo.columns.count'|trans }}</th>
                            <th scope="col">{{ 'admin.homepage.todo.columns.status'|trans }}</th>
                            <th scope="col" class="text-right">{{ 'admin.homepage.todo.columns.action'|trans }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% if is_granted('ROLE_ORDER') or is_granted('ROLE_ADMIN') %}
                            <tr>
                                <td>
                                    <i class="fas fa-undo-alt text-muted" aria-hidden="true"></i>
                                    <strong>{{ 'admin.homepage.todo.withdrawals.label'|trans }}</strong>
                                    <br>
                                    <small class="text-muted">{{ 'admin.homepage.todo.withdrawals.description'|trans }}</small>
                                </td>
                                <td class="text-center">
                                    <span class="badge">{{ todo.withdrawals }}</span>
                                </td>
                                <td>
                                    <span class="label {{ todo.withdrawals > 0 ? 'label-warning' : 'label-success' }}">
                                        {{ (todo.withdrawals > 0 ? 'admin.homepage.todo.status.pending' : 'admin.homepage.todo.status.clear')|trans }}
                                    </span>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-default btn-sm" href="{{ path('admin_withdrawal', { status: 'pending' }) }}">
                                        {{ 'admin.homepage.todo.action'|trans }}
                                    </a>
                                </td>
                            </tr>
                        {% endif %}

                        {% if is_granted('ROLE_MARKETING') or is_granted('ROLE_ADMIN') %}
                            <tr>
                                <td>
                                    <i class="fas fa-star text-muted" aria-hidden="true"></i>
                                    <strong>{{ 'admin.homepage.todo.reviews.label'|trans }}</strong>
                                    <br>
                                    <small class="text-muted">{{ 'admin.homepage.todo.reviews.description'|trans }}</small>
                                </td>
                                <td class="text-center">
                                    <span class="badge">{{ todo.reviews }}</span>
                                </td>
                                <td>
                                    <span class="label {{ todo.reviews > 0 ? 'label-warning' : 'label-success' }}">
                                        {{ (todo.reviews > 0 ? 'admin.homepage.todo.status.pending' : 'admin.homepage.todo.status.clear')|trans }}
                                    </span>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-default btn-sm" href="{{ path('admin_marketing_product_reviews', { status: 'pending' }) }}">
                                        {{ 'admin.homepage.todo.action'|trans }}
                                    </a>
                                </td>
                            </tr>
                        {% endif %}

                        {% if is_granted('ROLE_ORDER') or is_granted('ROLE_ADMIN') %}
                            <tr>
                                <td>
                                    <i class="fas fa-money-check-alt text-muted" aria-hidden="true"></i>
                                    <strong>{{ 'admin.homepage.todo.offline_payments.label'|trans }}</strong>
                                    <br>
                                    <small class="text-muted">{{ 'admin.homepage.todo.offline_payments.description'|trans }}</small>
                                </td>
                                <td class="text-center">
                                    <span class="badge">{{ todo.offlinePayments }}</span>
                                </td>
                                <td>
                                    <span class="label {{ todo.offlinePayments > 0 ? 'label-warning' : 'label-success' }}">
                                        {{ (todo.offlinePayments > 0 ? 'admin.homepage.todo.status.pending' : 'admin.homepage.todo.status.clear')|trans }}
                                    </span>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-default btn-sm" href="{{ path('admin_order', { status: 'offline_pending' }) }}">
                                        {{ 'admin.homepage.todo.action'|trans }}
                                    </a>
                                </td>
                            </tr>

                            <tr>
                                <td>
                                    <i class="fas fa-truck text-muted" aria-hidden="true"></i>
                                    <strong>{{ 'admin.homepage.todo.deliveries.label'|trans }}</strong>
                                    <br>
                                    <small class="text-muted">{{ 'admin.homepage.todo.deliveries.description'|trans }}</small>
                                </td>
                                <td class="text-center">
                                    <span class="badge">{{ todo.deliveries }}</span>
                                </td>
                                <td>
                                    <span class="label {{ todo.deliveries > 0 ? 'label-warning' : 'label-success' }}">
                                        {{ (todo.deliveries > 0 ? 'admin.homepage.todo.status.pending' : 'admin.homepage.todo.status.clear')|trans }}
                                    </span>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-default btn-sm" href="{{ path('admin_order', { status: 'paid_not_delivered' }) }}">
                                        {{ 'admin.homepage.todo.action'|trans }}
                                    </a>
                                </td>
                            </tr>
                        {% endif %}
                    </tbody>
                </table>
            </div>
        </div>
    {% endif %}

    <div class="row">
        {% if is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fas fa-users fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Clients</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_client') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Voir la liste</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if is_granted('ROLE_ORDER') or is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-green">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fas fa-list-ul fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Commandes</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_order') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Voir l'historique</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if is_granted('ROLE_PRODUCT') or is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-yellow">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fab fa-product-hunt fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Produits</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_product') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Voir la liste</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-red">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fas fa-user-shield fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Admins</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_user') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Gérer les accès</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if is_granted('ROLE_POPUP') or is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="far fa-window-restore fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Annonces</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_popup') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Voir la liste</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if is_granted('ROLE_PROMO') or is_granted('ROLE_ADMIN') %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-yellow">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fas fa-percent fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Codes promo</div>
                            </div>
                        </div>
                    </div>
                    <a href="{{ path('admin_promo') }}">
                        <div class="panel-footer">
                            <span class="pull-left">Voir la liste</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}

        {% if shopConfig and shopConfig.matomoConfigured %}
            <div class="col-lg-3 col-md-6">
                <div class="panel panel-green">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-3">
                                <i class="fas fa-chart-line fa-3x"></i>
                            </div>
                            <div class="col-xs-9 text-right">
                                <div>Visites</div>
                            </div>
                        </div>
                    </div>
                    <a href="https://matomo.cpcreation.net/" target="_blank" rel="noopener noreferrer">
                        <div class="panel-footer">
                            <span class="pull-left">Voir les statistiques</span>
                            <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
                            <div class="clearfix"></div>
                        </div>
                    </a>
                </div>
            </div>
        {% endif %}
    </div>
{% endblock %}
