{% extends "base.html" %}

{% block title %}{{ staff.full_name }} - 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-person me-2"></i>{{ staff.full_name }}</h4>
    <div>
      <a href="{{ url_for('ent.staff') }}" class="btn btn-outline-secondary btn-sm">
        <i class="bi bi-arrow-left me-1"></i>Retour
      </a>
    </div>
  </div>

  <div class="row">
    <!-- Informations -->
    <div class="col-lg-4">
      <div class="card shadow-sm mb-4">
        <div class="card-header bg-primary text-white">
          <i class="bi bi-person-badge me-2"></i>Informations
        </div>
        <div class="card-body">
          <table class="table table-sm mb-0">
            <tr><td class="text-muted">Prénom</td><td>{{ staff.first_name }}</td></tr>
            <tr><td class="text-muted">Nom</td><td>{{ staff.last_name }}</td></tr>
            <tr><td class="text-muted">Fonction</td><td>{{ staff.function or '—' }}</td></tr>
            <tr><td class="text-muted">Service</td><td>{{ staff.department or '—' }}</td></tr>
            <tr><td class="text-muted">Email</td><td>{{ staff.email or '—' }}</td></tr>
            <tr><td class="text-muted">Téléphone</td><td>{{ staff.phone or '—' }}</td></tr>
            <tr>
              <td class="text-muted">Statut</td>
              <td>
                {% if staff.is_active %}
                <span class="badge bg-success">Actif</span>
                {% else %}
                <span class="badge bg-secondary">Inactif</span>
                {% endif %}
              </td>
            </tr>
          </table>
        </div>
      </div>

      <!-- Statistiques -->
      <div class="card shadow-sm">
        <div class="card-header bg-dark text-white">
          <i class="bi bi-bar-chart me-2"></i>Statistiques
        </div>
        <div class="card-body text-center">
          <div class="row">
            <div class="col-6">
              <h3 class="mb-0">{{ staff.intervention_count }}</h3>
              <small class="text-muted">Demandes total</small>
            </div>
            <div class="col-6">
              <h3 class="mb-0 {% if staff.open_intervention_count > 0 %}text-warning{% else %}text-success{% endif %}">
                {{ staff.open_intervention_count }}
              </h3>
              <small class="text-muted">En cours</small>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Historique des demandes -->
    <div class="col-lg-8">
      <div class="card shadow-sm">
        <div class="card-header">
          <i class="bi bi-list-task me-2"></i>Historique des demandes ({{ interventions|length }})
        </div>
        <div class="table-responsive">
          {% if interventions %}
          <table class="table table-hover align-middle mb-0">
            <thead class="table-light">
              <tr>
                <th>N°</th>
                <th>Titre</th>
                <th>Statut</th>
                <th>Priorité</th>
                <th>Date</th>
              </tr>
            </thead>
            <tbody>
              {% for interv in interventions %}
              <tr>
                <td>
                  <a href="{{ url_for('interventions.detail', id=interv.id) }}" class="text-decoration-none">
                    #{{ interv.id }}
                  </a>
                </td>
                <td>{{ interv.title[:50] }}{% if interv.title|length > 50 %}…{% endif %}</td>
                <td>
                  <span class="badge bg-{{ interv.status_color }}">
                    {{ interv.status_label }}
                  </span>
                </td>
                <td>
                  <span class="badge bg-{{ interv.priority_color }}">
                    {{ interv.priority_label }}
                  </span>
                </td>
                <td class="small">
                  {{ interv.requested_at.strftime('%d/%m/%Y') if interv.requested_at else '—' }}
                </td>
              </tr>
              {% endfor %}
            </tbody>
          </table>
          {% else %}
          <div class="text-center py-4">
            <i class="bi bi-inbox display-4 text-muted"></i>
            <p class="text-muted mt-2">Aucune demande liée à ce personnel.</p>
          </div>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}
