{% extends 'pdf/_base.html.twig' %}

{% block title %}Log #{{ log.id }} - Association E-Cosplay{% endblock %}
{% block data_table_mt %}8px{% endblock %}
{% block data_td_pad %}5px{% endblock %}

{% block extra_styles %}
        .info-cell { border-left: 3px solid #4338ca; }
        .doc-type { background: #4338ca; }
        .hmac-box { margin: 16px 0; padding: 12px; border: 2px solid;  }
        .hmac-box.ok { border-color: #16a34a; background: #f0fdf4; }
        .hmac-box.ko { border-color: #dc2626; background: #fef2f2; }
        .hmac-ok { color: #16a34a; font-weight: 700; font-size: 12px; }
        .hmac-ko { color: #dc2626; font-weight: 700; font-size: 12px; }
        .mono { font-family: monospace; font-size: 9px; word-break: break-all; }
{% endblock %}

{% block content %}
        <span class="doc-type">Log d'activite</span>
        <h1>Rapport de log #{{ log.id }}</h1>
        <div class="subtitle">Trace d'activite &mdash; CRM E-Cosplay</div>

        <div class="info-grid">
            <div class="info-row">
                <div class="info-cell" style="width: 25%;"><span class="info-label">ID</span><span class="info-value">#{{ log.id }}</span></div>
                <div class="info-cell" style="width: 25%;"><span class="info-label">Date</span><span class="info-value">{{ log.createdAt|date('d/m/Y a H:i:s') }}</span></div>
                <div class="info-cell" style="width: 25%;"><span class="info-label">Methode</span><span class="info-value">{{ log.method }}</span></div>
                <div class="info-cell" style="width: 25%;"><span class="info-label">Adresse IP</span><span class="info-value">{{ log.ip ?? 'N/A' }}</span></div>
            </div>
        </div>

        <h2>Utilisateur</h2>
        <table class="data">
            <thead><tr><th>Champ</th><th>Valeur</th></tr></thead>
            <tbody>
                {% if log.user %}
                    <tr><td>Nom complet</td><td><strong>{{ log.user.fullName }}</strong></td></tr>
                    <tr><td>Email</td><td class="mono">{{ log.user.email }}</td></tr>
                    <tr><td>ID utilisateur</td><td>{{ log.user.id }}</td></tr>
                {% else %}
                    <tr><td>Utilisateur</td><td><em>Non connecte</em></td></tr>
                {% endif %}
            </tbody>
        </table>

        <h2>Requete</h2>
        <table class="data">
            <thead><tr><th>Champ</th><th>Valeur</th></tr></thead>
            <tbody>
                <tr><td>Methode HTTP</td><td><strong>{{ log.method }}</strong></td></tr>
                <tr><td>URL</td><td class="mono">{{ log.url }}</td></tr>
                <tr><td>Route</td><td class="mono">{{ log.route }}</td></tr>
                <tr><td>Action</td><td><strong>{{ log.action }}</strong></td></tr>
                <tr><td>Adresse IP</td><td class="mono">{{ log.ip ?? 'N/A' }}</td></tr>
                <tr><td>Date et heure</td><td>{{ log.createdAt|date('d/m/Y H:i:s') }}</td></tr>
            </tbody>
        </table>

        <h2>Integrite</h2>
        <div class="hmac-box {{ hmacValid ? 'ok' : 'ko' }}">
            {% if hmacValid %}
                <span class="hmac-ok">&#10003; INTEGRITE VERIFIEE &mdash; DONNEES CONFORMES</span>
                <p style="font-size: 9px; color: #666; margin: 4px 0 0;">Les donnees de ce log n'ont pas ete alterees depuis leur enregistrement.</p>
            {% else %}
                <span class="hmac-ko">&#10007; INTEGRITE COMPROMISE &mdash; DONNEES ALTEREES</span>
                <p style="font-size: 9px; color: #991b1b; margin: 4px 0 0;">Attention : les donnees de ce log ont ete modifiees apres leur enregistrement initial.</p>
            {% endif %}
        </div>
{% endblock %}

{% block hmac_section %}
        <div class="hmac">HMAC-SHA256 : {{ log.hmac }}</div>
{% endblock %}

{% block verify_box %}
        {% if verifyUrl is defined and qrcode is defined %}
        <div style="margin: 16px 0; border: 1px solid #ddd;  display: table; width: 100%;">
            <div style="display: table-row;">
                <div style="display: table-cell; text-align: center; width: 100px; padding: 8px; border-right: 2px solid #111827; vertical-align: middle;">
                    <img src="{{ qrcode }}" alt="QR Code" style="width: 72px; height: 72px;">
                </div>
                <div style="display: table-cell; padding: 8px 12px; font-size: 9px; vertical-align: middle;">
                    <span style="font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: #999; display: block; margin-bottom: 1px;">Verifier ce document</span>
                    <p style="margin: 2px 0 4px; font-size: 9px; font-weight: 700;">Scannez le QR code ou consultez le lien ci-dessous.</p>
                    <span style="font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: #999; display: block; margin-bottom: 1px;">URL</span>
                    <span style="font-size: 8px; font-family: monospace; color: #4338ca; word-break: break-all;">{{ verifyUrl }}</span>
                </div>
            </div>
        </div>
        {% endif %}
{% endblock %}

{% block footer_contact %}
        <div style="margin-top: 24px;">
            <span class="contact-box">client@e-cosplay.fr</span>
        </div>
{% endblock %}

{% block signature_box %}{% endblock %}

{% block footer_legal %}
            Association E-Cosplay &mdash; Siret : 943 121 517 &mdash; TVA : FR05 943 121 517<br>
            42 rue de Beautor, 02800 Beautor, France &mdash; client@e-cosplay.fr<br>
            <a href="https://www.e-cosplay.fr" style="color: #999;">www.e-cosplay.fr</a>
{% endblock %}
