{% extends "base.html" %}

{% block title %}Personnels - 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-people me-2"></i>Personnels</h4>
    <a href="{{ url_for('ent.staff') }}" class="btn btn-primary">
      <i class="bi bi-person-plus me-1"></i>Ajouter
    </a>
  </div>

  <!-- Personnels actifs -->
  {% if staff_list %}
  <div class="card shadow-sm mb-4">
    <div class="card-header bg-success text-white">
      <i class="bi bi-people-fill me-2"></i>Personnels actifs ({{ staff_list|length }})
    </div>
    <div class="table-responsive">
      <table class="table table-hover align-middle mb-0">
        <thead class="table-light">
          <tr>
            <th>Nom</th>
            <th>Fonction</th>
            <th>Service</th>
            <th class="text-center">Demandes</th>
            <th class="text-center">Ouvertes</th>
            <th>Contact</th>
            <th style="width:120px;"></th>
          </tr>
        </thead>
        <tbody>
          {% for s in staff_list %}
          <tr>
            <td>
              <a href="{{ url_for('ent.staff_detail', id=s.id) }}" class="text-decoration-none fw-bold">
                {{ s.last_name }} {{ s.first_name }}
              </a>
            </td>
            <td>{{ s.function or '—' }}</td>
            <td>{{ s.department or '—' }}</td>
            <td class="text-center">
              <span class="badge bg-primary rounded-pill">{{ s.intervention_count }}</span>
            </td>
            <td class="text-center">
              {% if s.open_intervention_count > 0 %}
              <span class="badge bg-warning rounded-pill">{{ s.open_intervention_count }}</span>
              {% else %}
              <span class="badge bg-success rounded-pill">0</span>
              {% endif %}
            </td>
            <td>
              {% if s.email %}<i class="bi bi-envelope me-1"></i>{{ s.email }}{% endif %}
              {% if s.phone %}<br><i class="bi bi-telephone me-1"></i>{{ s.phone }}{% endif %}
              {% if not s.email and not s.phone %}<span class="text-muted">—</span>{% endif %}
            </td>
            <td>
              <span class="text-muted" title="Modification depuis l’ENT non disponible">—</span>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  {% else %}
  <div class="text-center py-4">
    <i class="bi bi-people display-4 text-muted"></i>
    <p class="text-muted mt-2">Aucun personnel enregistré.</p>
  </div>
  {% endif %}

  <!-- Personnels inactifs -->
  {% if inactive %}
  <div class="card shadow-sm border-secondary">
    <div class="card-header bg-secondary text-white">
      <i class="bi bi-people me-2"></i>Inactifs ({{ inactive|length }})
    </div>
    <div class="table-responsive">
      <table class="table table-hover align-middle mb-0 small">
        <thead class="table-light">
          <tr>
            <th>Nom</th>
            <th>Fonction</th>
            <th class="text-center">Demandes</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for s in inactive %}
          <tr class="text-muted">
            <td>{{ s.last_name }} {{ s.first_name }}</td>
            <td>{{ s.function or '—' }}</td>
            <td class="text-center">{{ s.intervention_count }}</td>
            <td>
              <span class="text-muted" title="Modification depuis l’ENT non disponible">—</span>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  {% endif %}
</div>
{% endblock %}
