{% extends "index.html" %}
{% block title %}Relatórios{% endblock %}
{% block content %}
<h1>📊 Relatórios</h1>

<form method="get" style="margin-bottom: 20px;">
  <label for="cliente">Filtrar por Cliente:</label>
  <select name="cliente" id="cliente" onchange="this.form.submit()">
    <option value="">Todos</option>
    {% for c in clientes %}
      <option value="{{ c }}" {% if c == cliente_atual %}selected{% endif %}>{{ c }}</option>
    {% endfor %}
  </select>
</form>

<table style="width: 100%; border-collapse: collapse;">
  <thead>
    <tr style="background: #2563eb; color: white;">
      <th style="padding: 10px;">Cliente</th>
      <th>Data</th>
      <th>Valor Total</th>
      <th>ICMS na Base</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    {% for f in faturas %}
    <tr style="background: {{ loop.cycle('#ffffff', '#f0f4f8') }};">
      <td style="padding: 10px;">{{ f.nome }}</td>
      <td>{{ f.data_emissao }}</td>
      <td>R$ {{ '%.2f'|format(f.valor_total)|replace('.', ',') }}</td>
      <td>{{ 'Sim' if f.com_icms else 'Não' }}</td>
      <td>{{ f.status }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
