{% extends "base.html" %}
{% block title %}Passages & contrôles{% endblock %}
{% block content %}
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-3"><div><h1 class="h3">Passages &amp; contrôles</h1><p class="text-muted mb-0">Suivez les visites des entreprises sans confondre date prévue et passage réellement réalisé.</p></div><a class="btn btn-outline-secondary" href="{{ url_for('contracts.index') }}">Contrats</a></div>
  <div class="btn-group mb-3" role="group" aria-label="Filtrer les passages"><a class="btn btn-outline-secondary {{ 'active' if not status }}" href="{{ url_for('contracts.visits_dashboard') }}">Tous</a>{% for value,label in [('planifiee','À planifier'),('passage_libre','Passages libres'),('entreprise_arrivee','Arrivées'),('non_venue','Non venues'),('realisee','Réalisés')] %}<a class="btn btn-outline-secondary {{ 'active' if status == value }}" href="{{ url_for('contracts.visits_dashboard', status=value) }}">{{ label }}</a>{% endfor %}</div>
  <div class="row g-3">{% for visit in visits %}<div class="col-md-6 col-xl-4"><article class="card h-100 shadow-sm"><div class="card-body"><div class="d-flex justify-content-between"><h2 class="h6 mb-1">{{ visit.contract.company.name if visit.contract.company else 'Entreprise non définie' }}</h2><span class="badge bg-{{ 'success' if visit.status == 'realisee' else ('danger' if visit.scheduled_date < today and visit.status not in ('realisee','annulee') else 'primary') }}">{{ visit.status|replace('_',' ') }}</span></div><p class="mb-1"><strong>{{ visit.contract.name }}</strong></p><p class="small text-muted mb-1">{{ visit.display_mode }} · prévu le {{ visit.scheduled_date.strftime('%d/%m/%Y') }}{% if visit.start_time %} à {{ visit.start_time.strftime('%H:%M') }}{% endif %}</p>{% if visit.actual_date %}<p class="small mb-0">Passage réel : {{ visit.actual_date.strftime('%d/%m/%Y') }}</p>{% endif %}{% if visit.accompaniment_mode != 'none' %}<p class="small mb-0">Accompagnement technicien : {{ visit.accompaniment_minutes or ('toute la durée' if visit.accompaniment_mode == 'full' else 'ponctuel') }}</p>{% endif %}</div><div class="card-footer bg-transparent"><a href="{{ url_for('contracts.detail', id=visit.contract_id) }}" class="btn btn-sm btn-outline-primary">Voir le contrat</a></div></article></div>{% else %}<div class="col-12"><div class="alert alert-info">Aucun passage ne correspond à ce filtre.</div></div>{% endfor %}</div>
</div>
{% endblock %}
