{% extends 'legal/_layout.html.twig' %}

{% block title %}Verification log #{{ id }} - Association E-Cosplay{% endblock %}
{% block description %}Verification de l'integrite du log #{{ id }}.{% endblock %}

{% block body %}
<div class="page-container">
    <h1 class="text-2xl font-bold heading-page mb-8">Verification de log</h1>

    <div class="flex flex-col gap-8">

        {% if log is null %}
            <div class="glass p-6" style="border-left: 4px solid #dc2626;">
                <div class="flex items-center gap-3 mb-2">
                    <svg class="w-8 h-8 text-red-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M6 18L18 6M6 6l12 12"/></svg>
                    <span class="text-xl font-bold uppercase text-red-800">Log introuvable</span>
                </div>
                <p class="text-sm text-red-700">Le log #{{ id }} n'existe pas ou le lien de verification est invalide.</p>
            </div>
        {% elseif valid %}
            <div class="glass p-6" style="border-left: 4px solid #16a34a;">
                <div class="flex items-center gap-3 mb-2">
                    <svg class="w-8 h-8 text-green-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/></svg>
                    <span class="text-xl font-bold uppercase text-green-800">Integrite verifiee</span>
                </div>
                <p class="text-sm text-green-700 font-bold">La signature HMAC-SHA256 de ce log a ete verifiee avec succes. Les donnees sont conformes et n'ont pas ete alterees.</p>
            </div>
        {% else %}
            <div class="glass p-6" style="border-left: 4px solid #dc2626;">
                <div class="flex items-center gap-3 mb-2">
                    <svg class="w-8 h-8 text-red-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M6 18L18 6M6 6l12 12"/></svg>
                    <span class="text-xl font-bold uppercase text-red-800">Integrite compromise</span>
                </div>
                <p class="text-sm text-red-700 font-bold">La signature de ce log est invalide. Les donnees ont ete modifiees apres leur enregistrement initial.</p>
            </div>
        {% endif %}

        {% if log %}
            <div class="glass overflow-hidden">
                <div class="glass-dark text-white px-6 py-3" >
                    <span class="text-xs font-bold uppercase tracking-wider">Details du log #{{ log.id }}</span>
                </div>
                <div class="p-6">
                    <table class="w-full text-sm">
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 w-1/3 text-left">ID</th>
                            <td class="py-3 font-bold">#{{ log.id }}</td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Date</th>
                            <td class="py-3 font-bold">{{ log.createdAt|date('d/m/Y a H:i:s') }}</td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Utilisateur</th>
                            <td class="py-3 font-bold">
                                {% if log.user %}
                                    {{ log.user.fullName }} ({{ log.user.email }})
                                {% else %}
                                    <span class="text-gray-400">Non connecte</span>
                                {% endif %}
                            </td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Methode</th>
                            <td class="py-3">
                                <span class="px-2 py-0.5text-xs font-bold
                                    {% if log.method == 'POST' %}bg-orange-500/20 text-orange-700
                                    {% elseif log.method == 'DELETE' %}bg-red-500/20 text-red-700
                                    {% else %}bg-gray-500/20 text-gray-600{% endif %}">
                                    {{ log.method }}
                                </span>
                            </td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Action</th>
                            <td class="py-3 font-bold">{{ log.action }}</td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">URL</th>
                            <td class="py-3 font-mono text-xs break-all">{{ log.url }}</td>
                        </tr>
                        <tr class="border-b border-white/20">
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Route</th>
                            <td class="py-3 font-mono text-xs">{{ log.route }}</td>
                        </tr>
                        <tr>
                            <th scope="row" class="py-3 pr-4 font-bold uppercase text-xs text-gray-500 text-left">Adresse IP</th>
                            <td class="py-3 font-mono text-xs">{{ log.ip ?? 'N/A' }}</td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="glass p-4">
                <p class="text-xs font-bold uppercase tracking-wider text-gray-400 mb-2">Signature HMAC-SHA256</p>
                <p class="text-xs font-mono text-gray-500 break-all">{{ log.hmac }}</p>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}
