{% extends 'base.html' %}
{% block title %}Résultats Déploiement{% endblock %}
{% block content %}
<div class="flex justify-between items-center mb-4">
    <div>
        <h2 class="text-xl font-bold text-cyber-accent">Résultats du déploiement</h2>
        <p class="text-xs text-gray-500 mt-1">{{ total }} serveur(s) traité(s)</p>
    </div>
    <a href="/qualys/deploy" class="btn-sm bg-cyber-border text-cyber-accent px-4 py-2">Retour</a>
</div>

<!-- KPIs -->
<div style="display:flex;gap:8px;margin-bottom:16px">
    <div class="card p-3 text-center" style="flex:1"><div class="text-2xl font-bold text-cyber-accent">{{ total }}</div><div class="text-xs text-gray-500">Total</div></div>
    {% if active is defined %}
    <div class="card p-3 text-center" style="flex:1"><div class="text-2xl font-bold text-cyber-green">{{ active }}</div><div class="text-xs text-gray-500">Actifs</div></div>
    <div class="card p-3 text-center" style="flex:1"><div class="text-2xl font-bold text-cyber-red">{{ not_installed }}</div><div class="text-xs text-gray-500">Non installés</div></div>
    {% else %}
    <div class="card p-3 text-center" style="flex:1"><div class="text-2xl font-bold text-cyber-green">{{ ok }}</div><div class="text-xs text-gray-500">Succès</div></div>
    <div class="card p-3 text-center" style="flex:1"><div class="text-2xl font-bold text-cyber-red">{{ failed }}</div><div class="text-xs text-gray-500">Échecs</div></div>
    {% endif %}
</div>

<!-- Résultats -->
<div class="card overflow-hidden mb-4">
    <table class="w-full table-cyber text-xs">
        <thead><tr>
            <th class="p-2 text-left">Hostname</th>
            <th class="p-2">Statut</th>
            <th class="p-2 text-left">Détail</th>
            {% if results and results[0].version is defined %}
            <th class="p-2">Version</th>
            <th class="p-2">Service</th>
            {% endif %}
        </tr></thead>
        <tbody>
        {% for r in results %}
        <tr class="border-t border-cyber-border/30">
            <td class="p-2 font-mono">{{ r.hostname }}</td>
            <td class="p-2 text-center">
                {% if r.status == 'SUCCESS' or r.status == 'ACTIVE' %}
                    <span class="badge badge-green">{{ r.status }}</span>
                {% elif r.status == 'ALREADY_INSTALLED' %}
                    <span class="badge badge-blue">DÉJÀ INSTALLÉ</span>
                {% elif r.status == 'NOT_INSTALLED' %}
                    <span class="badge badge-yellow">NON INSTALLÉ</span>
                {% elif r.status == 'INACTIVE' %}
                    <span class="badge badge-yellow">INACTIF</span>
                {% else %}
                    <span class="badge badge-red">{{ r.status }}</span>
                {% endif %}
            </td>
            <td class="p-2 text-gray-400">{{ r.detail or r.get('detail', '') }}</td>
            {% if r.version is defined %}
            <td class="p-2 text-center text-gray-400">{{ r.version or '-' }}</td>
            <td class="p-2 text-center">{{ r.service_status or '-' }}</td>
            {% endif %}
        </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

<!-- Log détaillé -->
{% if log_lines %}
<div class="card p-4">
    <h3 class="text-sm font-bold text-cyber-accent mb-2">Log détaillé</h3>
    <div style="background:#0a0a23;border-radius:6px;padding:12px;max-height:400px;overflow-y:auto;font-family:monospace;font-size:0.75rem;color:#00ff88;white-space:pre-wrap">{% for line in log_lines %}{{ line }}
{% endfor %}</div>
</div>
{% endif %}
{% endblock %}
