{% extends "base.html" %}

{% block title %}Visualisation des logs - GMAO{% endblock %}

{% block content %}
<div class="container-fluid py-4">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h4><i class="bi bi-file-earmark-text me-2"></i>Visualisation des logs</h4>
    <div class="alert alert-success">
      <i class="bi bi-shield-check me-2"></i>
      <strong>Accès admin uniquement</strong> - Les utilisateurs non-admin ne peuvent pas voir cette page
    </div>
  </div>

  <div class="card">
    <div class="card-header">
      <h6 class="mb-0"><i class="bi bi-journal-text me-2"></i>Logs système</h6>
    </div>
    <div class="card-body">
      {% if logs %}
        {% for log in logs %}
          <div class="mb-4">
            <div class="d-flex justify-content-between align-items-center mb-2">
              <h6 class="mb-0 text-primary">{{ log.file }}</h6>
              <small class="text-muted">Derniers 2000 caractères</small>
            </div>
            
            {% if log.error %}
              <div class="alert alert-warning">
                <i class="bi bi-exclamation-triangle me-2"></i>
                Erreur de lecture: {{ log.error }}
              </div>
            {% else %}
              <pre class="bg-light p-3 border rounded" style="max-height: 400px; overflow-y: auto; font-size: 0.85rem;">{{ log.content }}</pre>
            {% endif %}
          </div>
          {% if not loop.last %}<hr>{% endif %}
        {% endfor %}
      {% else %}
        <div class="alert alert-info">
          <i class="bi bi-info-circle me-2"></i>
          Aucun fichier log trouvé dans les emplacements configurés.
        </div>
      {% endif %}
    </div>
  </div>

  <div class="card mt-4">
    <div class="card-header">
      <h6><i class="bi bi-info-circle me-2"></i>Permissions actuelles</h6>
    </div>
    <div class="card-body">
      <div class="row">
        <div class="col-md-6">
          <strong>Utilisateur actuel :</strong> {{ current_user.username }} ({{ current_user.role_label }})
        </div>
        <div class="col-md-6">
          <strong>Permission code:edit :</strong> 
          {% if current_user.is_admin() %}
            <span class="badge bg-success">✅ Accordée</span>
          {% else %}
            <span class="badge bg-danger">❌ Refusée</span>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</div>

{% endblock %}
