{% extends 'base.html' %}
{% block title %}Historique validations — {{ server.hostname }}{% endblock %}
{% block content %}
<div class="flex justify-between items-center mb-4">
    <div>
        <a href="/patching/validations" class="text-xs text-gray-500 hover:text-gray-300">&larr; Validations</a>
        <h2 class="text-xl font-bold text-cyber-accent">Historique — <span class="font-mono">{{ server.hostname }}</span></h2>
    </div>
</div>

<div class="card overflow-x-auto">
    <table class="w-full table-cyber text-xs">
        <thead><tr>
            <th class="p-2">Patched</th>
            <th class="p-2">Campagne</th>
            <th class="p-2">Statut</th>
            <th class="p-2">Validé par</th>
            <th class="p-2">Le</th>
            <th class="p-2 text-left">Raison forcée</th>
            <th class="p-2 text-left">Notes</th>
            <th class="p-2">Marqué par</th>
        </tr></thead>
        <tbody>
        {% for h in history %}
        <tr class="border-t border-cyber-border/30">
            <td class="p-2 text-center">{{ h.patch_date.strftime('%Y-%m-%d %H:%M') if h.patch_date }}</td>
            <td class="p-2 text-center text-gray-400">{{ h.campaign_type or '-' }} #{{ h.campaign_id or '' }}</td>
            <td class="p-2 text-center">
                {% if h.status == 'en_attente' %}<span class="badge badge-yellow">En attente</span>
                {% elif h.status == 'validated_ok' %}<span class="badge badge-green">OK</span>
                {% elif h.status == 'validated_ko' %}<span class="badge badge-red">KO</span>
                {% elif h.status == 'forced' %}<span class="badge badge-yellow">Forcé</span>
                {% endif %}
            </td>
            <td class="p-2 text-center">{{ h.validated_by_name or '—' }}</td>
            <td class="p-2 text-center text-gray-400">{{ h.validated_at.strftime('%Y-%m-%d %H:%M') if h.validated_at else '—' }}</td>
            <td class="p-2 text-gray-300">{{ h.forced_reason or '' }}</td>
            <td class="p-2 text-gray-300">{{ h.notes or '' }}</td>
            <td class="p-2 text-center text-gray-400">{{ h.marked_by or '—' }}</td>
        </tr>
        {% endfor %}
        {% if not history %}
        <tr><td colspan="8" class="p-6 text-center text-gray-500">Aucun historique</td></tr>
        {% endif %}
        </tbody>
    </table>
</div>
{% endblock %}
