{% extends 'base.html' %}
{% block content %}
  <h2>Supplier Overview</h2>
  <div class="grid cols-3">
    <div class="card">
      <h3>Total Supplied</h3>
      <div class="stat">{{ total_supplied_kg|kg }}</div>
    </div>
    <div class="card">
      <h3>Payments Collected</h3>
      <div class="stat">{{ payments_collected|currency }}</div>
      <small style="color: #666;">From customers</small>
    </div>
    <div class="card">
      <h3>Payments Remitted</h3>
      <div class="stat">{{ payments_remitted|currency }}</div>
      <small style="color: #666;">To admin</small>
    </div>
  </div>

  <!-- Payment Actions -->
  <div class="card" style="margin-top: 16px;">
    <div style="display: flex; justify-content: space-between; align-items: center;">
      <h3>Payment Management</h3>
      <div style="display: flex; gap: 12px;">
        {% if payments_collected > 0 %}
          <a href="{{ url_for('supplier_remit_payment') }}" class="btn-primary">Remit Payment to Admin</a>
        {% endif %}
      </div>
    </div>
    <div style="margin-top: 12px; padding: 12px; background: #f8fafc; border-radius: 8px;">
      <p style="margin: 0; color: #666;">
        <strong>Available to Remit:</strong> {{ (payments_collected - payments_remitted)|currency }}
      </p>
    </div>
  </div>

  <div class="card" style="margin-top:16px">
    <h3>Recent Deliveries</h3>
    <table class="table">
      <thead><tr><th>Date</th><th>Customer</th><th>Weight</th><th>Price/kg</th><th>Total</th></tr></thead>
      <tbody>
        {% for s in recent_sales %}
        <tr>
          <td>{{ s.date }}</td>
          <td>{{ s.customer.name }}</td>
          <td>{{ s.weight_kg|kg }}</td>
          <td>{{ s.price_per_kg|currency }}</td>
          <td>{{ s.total_amount|currency }}</td>
        </tr>
        {% else %}
          <tr><td colspan="5" class="muted">No deliveries yet.</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% endblock %}


