{% extends "base.html" %}

{% block title %}Message ENT77 - GMAO{% endblock %}

{% block content %}
<div class="container-fluid py-4">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h5><i class="bi bi-envelope-open me-2"></i>Message ENT77</h5>
    <a href="{{ url_for('ent.inbox') }}" class="btn btn-outline-secondary btn-sm">
      <i class="bi bi-arrow-left me-1"></i>Retour à la boîte
    </a>
  </div>

  <div class="card shadow-sm mb-4">
    <div class="card-header d-flex justify-content-between align-items-center">
      <div>
        <strong>{{ message.subject }}</strong>
        {% if message.is_forwarded %}
        <span class="badge bg-info ms-2">Transféré</span>
        {% endif %}
      </div>
      <small class="text-muted">{{ message.date|datetime_fmt if message.date else '—' }}</small>
    </div>
    <div class="card-body">
      <div class="row mb-3">
        <div class="col-md-6">
          <small class="text-muted">Expéditeur</small><br>
          <strong>{{ message.sender_name }}</strong>
        </div>
        {% if message.is_forwarded and message.original_sender %}
        <div class="col-md-6">
          <small class="text-muted">Expéditeur original (transféré)</small><br>
          <strong class="text-primary">{{ message.original_sender }}</strong>
        </div>
        {% endif %}
      </div>

      {% if message.has_attachment %}
      <div class="alert alert-secondary py-2 small">
        <i class="bi bi-paperclip me-1"></i>Ce message contient des pièces jointes.
      </div>
      {% endif %}

      <hr>
      <div class="message-body">
        {{ message.body|safe }}
      </div>
    </div>
  </div>

  {% if message.intervention_id %}
  <div class="card shadow-sm border-success">
    <div class="card-header bg-success text-white">
      <i class="bi bi-wrench me-2"></i>Intervention créée automatiquement
    </div>
    <div class="card-body">
      <a href="{{ url_for('interventions.detail', id=message.intervention_id) }}"
         class="btn btn-success">
        <i class="bi bi-box-arrow-up-right me-1"></i>Voir l'intervention #{{ message.intervention_id }}
      </a>
    </div>
  </div>
  {% else %}
  <div class="card shadow-sm border-secondary">
    <div class="card-header bg-secondary text-white">
      <i class="bi bi-info-circle me-2"></i>Aucune intervention créée
    </div>
    <div class="card-body">
      <p class="text-muted mb-0">Ce message n'a pas donné lieu à une intervention (information simple ou auto-création désactivée).</p>
    </div>
  </div>
  {% endif %}
</div>
{% endblock %}