{% extends "base.html" %}
{% block title %}Restaurer — {{ archive_name }}{% endblock %}

{% block content %}
<div class="max-w-2xl">
  <div class="mb-6">
    <a href="{{ url_for('jobs.index') }}" class="text-gray-400 hover:text-gray-600 text-sm">← Dashboard</a>
  </div>

  <div class="bg-white rounded-xl border border-gray-200 shadow-sm p-6 space-y-5">
    <div>
      <h1 class="text-xl font-bold text-gray-900">Confirmer la restauration</h1>
      <p class="text-sm text-gray-500 mt-1">Cette opération écrase les fichiers en place.</p>
    </div>

    <div class="bg-gray-50 rounded-lg p-4 space-y-2 text-sm">
      <div class="flex justify-between">
        <span class="text-gray-500">Archive</span>
        <span class="font-mono font-medium text-gray-800">{{ archive_name }}</span>
      </div>
      {% if info %}
        <div class="flex justify-between">
          <span class="text-gray-500">Type</span>
          <span class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded font-mono">{{ info.get('type', '—') }}</span>
        </div>
        {% if info.get('source_path') %}
        <div class="flex justify-between">
          <span class="text-gray-500">Chemin</span>
          <span class="font-mono text-gray-800">{{ info.get('source_path') }}</span>
        </div>
        {% endif %}
        {% if info.get('database') %}
        <div class="flex justify-between">
          <span class="text-gray-500">Base de données</span>
          <span class="font-mono text-gray-800">{{ info.get('database') }}</span>
        </div>
        {% endif %}
        <div class="flex justify-between">
          <span class="text-gray-500">Créée le</span>
          <span class="text-gray-700">{{ info.get('created_at', '—') }}</span>
        </div>
        <div class="flex justify-between">
          <span class="text-gray-500">Instance source</span>
          <span class="text-gray-700">{{ info.get('instance_name', '—') }}</span>
        </div>
      {% else %}
        <p class="text-gray-400 italic">Métadonnées indisponibles.</p>
      {% endif %}
    </div>

    {% set restore = info.get('restore', {}) if info else {} %}
    {% if restore %}
    <div class="space-y-2">
      <p class="text-sm font-semibold text-gray-700">Actions de restauration :</p>
      <ul class="text-sm text-gray-600 space-y-1 pl-4">
        {% if restore.get('system_user') %}
          <li class="flex items-center gap-2">
            <span class="text-green-500">✓</span>
            Création utilisateur système <code class="bg-gray-100 px-1 rounded text-xs">{{ restore.system_user.name }}</code>
            (si inexistant)
          </li>
        {% endif %}
        {% if restore.get('permissions') %}
          <li class="flex items-center gap-2">
            <span class="text-green-500">✓</span>
            Permissions :
            {% if restore.permissions.get('owner') %}<code class="bg-gray-100 px-1 rounded text-xs">chown {{ restore.permissions.owner }}</code>{% endif %}
            {% if restore.permissions.get('mode') %}<code class="bg-gray-100 px-1 rounded text-xs">chmod {{ restore.permissions.mode }}</code>{% endif %}
          </li>
        {% endif %}
        {% if restore.get('systemd_service') %}
          <li class="flex items-center gap-2">
            <span class="text-green-500">✓</span>
            Service systemd <code class="bg-gray-100 px-1 rounded text-xs">{{ restore.systemd_service.name }}</code>
            activé et démarré
          </li>
        {% endif %}
        {% for cmd in restore.get('post_restore_commands', []) %}
          <li class="flex items-center gap-2">
            <span class="text-blue-500">→</span>
            <code class="bg-gray-100 px-1 rounded text-xs">{{ cmd }}</code>
          </li>
        {% endfor %}
      </ul>
    </div>
    {% endif %}

    <div class="bg-amber-50 border border-amber-200 rounded-lg px-4 py-3 text-sm text-amber-800">
      ⚠ Les fichiers existants dans le chemin de destination seront <strong>écrasés</strong>.
      Cette action ne peut pas être annulée.
    </div>

    <form method="post" class="flex gap-3">
      <button type="submit"
              class="inline-flex items-center gap-1.5 bg-red-600 hover:bg-red-700 text-white font-semibold rounded-full shadow-sm transition btn-md">
        Confirmer la restauration
      </button>
      <a href="{{ url_for('jobs.index') }}" class="btn-secondary btn-md">Annuler</a>
    </form>
  </div>
</div>
{% endblock %}
