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

{% block title %}Logs{% endblock %}

{% block body %}
<div class="mb-8">
    <h1 class="text-3xl font-black uppercase tracking-tighter italic heading-page">Audit trail</h1>
    <p class="font-bold text-gray-500 italic">{{ logs.getTotalItemCount }} action{{ logs.getTotalItemCount > 1 ? 's' : '' }}.</p>
</div>

<div class="admin-card !p-0">
    <table class="admin-table">
        <thead>
            <tr>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Date</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Action</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Entite</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Details</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Par</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">IP</th>
            </tr>
        </thead>
        <tbody>
            {% for log in logs %}
            <tr class="hover:bg-gray-50 transition-all">
                <td class="text-xs text-gray-500 whitespace-nowrap">{{ log.createdAt|date('d/m/Y H:i:s') }}</td>
                <td>
                    {% if log.action == 'order_created' %}
                        <span class="admin-badge-yellow text-xs font-black uppercase">Commande</span>
                    {% elseif log.action == 'order_paid' %}
                        <span class="admin-badge-green text-xs font-black uppercase">Payee</span>
                    {% elseif log.action == 'order_cancelled' %}
                        <span class="admin-badge-red text-xs font-black uppercase">Annulee</span>
                    {% elseif log.action == 'order_refunded' %}
                        <span class="admin-badge-yellow text-xs font-black uppercase">Remboursee</span>
                    {% else %}
                        <span class="admin-badge-indigo text-xs font-black uppercase">{{ log.action }}</span>
                    {% endif %}
                </td>
                <td class="text-xs text-gray-600">{{ log.entityType }} #{{ log.entityId }}</td>
                <td class="text-xs text-gray-500">
                    {% for key, value in log.data %}
                        <span class="font-bold">{{ key }}</span>: {{ value }}{% if not loop.last %}, {% endif %}
                    {% endfor %}
                </td>
                <td class="text-xs text-gray-600">{{ log.performedBy ?? '—' }}</td>
                <td class="text-xs text-gray-400 font-mono">{{ log.ipAddress ?? '—' }}</td>
            </tr>
            {% else %}
            <tr>
                <td colspan="6" class="!text-center !py-12 text-gray-400 font-bold text-sm">Aucun log.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

{% if logs.getTotalItemCount > 30 %}
<div class="flex justify-center gap-2 mt-6">
    {% for page in 1..logs.getPageCount %}
        {% if page == logs.getCurrentPageNumber %}
            <span class="admin-page-active text-xs font-black">{{ page }}</span>
        {% else %}
            <a href="{{ path('app_admin_logs', {page: page}) }}" class="admin-page-link text-xs font-black hover:bg-gray-100 transition-all">{{ page }}</a>
        {% endif %}
    {% endfor %}
</div>
{% endif %}
{% endblock %}
