{% extends 'base.html' %}
{% block title %}Surveillance des compteurs{% endblock %}
{% block content %}
<div class="container py-3">
  <h1 class="h3">Surveillance des compteurs</h1>
  <p class="text-muted">Synthèses informatives du {{ period_start.strftime('%d/%m/%Y') }} au {{ period_end.strftime('%d/%m/%Y') }}.</p>
  <div class="row g-3 mb-3"><div class="col-md-3"><div class="card"><div class="card-body"><strong>Alertes critiques</strong><div class="fs-3">{{ alerts|selectattr('level','equalto','CRITICAL')|list|length }}</div></div></div></div><div class="col-md-3"><div class="card"><div class="card-body"><strong>Avertissements</strong><div class="fs-3">{{ alerts|selectattr('level','equalto','WARNING')|list|length }}</div></div></div></div><div class="col-md-3"><div class="card"><div class="card-body"><strong>Compteurs actifs</strong><div class="fs-3">{{ meters|length }}</div></div></div></div><div class="col-md-3"><div class="card"><div class="card-body"><strong>Données insuffisantes</strong><div class="fs-3">{{ insufficient_meters|length }}</div></div></div></div></div>
  <div class="row g-3 mb-3"><div class="col-md-4"><div class="card"><div class="card-body"><strong>Eau</strong><div>{{ '%.2f'|format(summaries.eau.raw) }} m³</div></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><strong>Gaz</strong><div>{{ '%.2f'|format(summaries.gaz.raw) }} m³</div><div>{% if summaries.gaz.kwh %}{{ '%.2f'|format(summaries.gaz.kwh) }} kWh convertis{% else %}kWh non calculés{% endif %}</div></div></div></div><div class="col-md-4"><div class="card"><div class="card-body"><strong>Électricité</strong><div>{{ '%.2f'|format(summaries.electricite.raw) }} kWh</div></div></div></div></div>
  <div class="row g-3">
    <div class="col-lg-8"><div class="card"><div class="card-header">Compteurs</div><div class="table-responsive"><table class="table mb-0"><thead><tr><th>Compteur</th><th>Derniers intervalles</th><th>Action</th></tr></thead><tbody>
    {% for meter in meters %}<tr><td>{{ meter.name }}<small class="d-block text-muted">{{ meter.unit }} · {{ meter.usage or 'Usage non renseigné' }}</small></td><td>{{ reading_counts.get(meter.id, 0) }}</td><td><a class="btn btn-sm btn-outline-primary" href="{{ url_for('planning.meter_analytics', meter_id=meter.id) }}">Analyser</a></td></tr>{% else %}<tr><td colspan="3">Aucun compteur actif.</td></tr>{% endfor %}
    </tbody></table></div></div></div>
    <div class="col-lg-4"><div class="card"><div class="card-header">Alertes ouvertes</div><ul class="list-group list-group-flush">{% for alert in alerts %}<li class="list-group-item"><span class="badge {% if alert.level == 'CRITICAL' %}bg-danger{% else %}bg-warning text-dark{% endif %}">{{ 'Critique' if alert.level == 'CRITICAL' else 'Avertissement' }}</span> {{ alert.meter.name }}<small class="d-block">{{ alert.alert_type }} · {{ alert.observed_value }}</small></li>{% else %}<li class="list-group-item text-muted">Aucune alerte ouverte.</li>{% endfor %}</ul></div></div>
  </div>
</div>
{% endblock %}
