{% extends "admin_frontend/base.html" %}
{% load crispy_forms_tags breadcrumbs %}
{% block title %}Weigh Tickets{% endblock %}
{% block content %}
{% render_breadcrumbs breadcrumbs %}
<div class="flex items-center justify-between mb-4">
  <h1 class="text-2xl font-semibold">Weigh Tickets</h1>
</div>

<div class="bg-white rounded shadow p-4 mb-4">
  <form method="get" class="space-y-3 flex gap-2">
    {{ filter.form|crispy }}
    <div class="flex items-center gap-2">
      <button class="px-3 py-2 bg-blue-600 text-white rounded">Filter</button>
      <a href="{% url 'recycle_core:weigh_tickets_list' %}" class="btn-outline">Reset</a>
    </div>
  </form>
  {% if filter.qs.count != page_obj.paginator.count %}
    <p class="text-sm text-gray-500 mt-2">Filtered results: {{ page_obj.paginator.count }} items</p>
  {% endif %}
</div>

<div class="bg-white rounded shadow overflow-hidden">
  <table class="min-w-full divide-y divide-gray-200">
    <thead class="bg-gray-50">
      <tr>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Ticket</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Customer</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Recorded</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Net</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Actions</th>
      </tr>
    </thead>
    <tbody class="divide-y divide-gray-200">
      {% for t in tickets %}
      <tr>
        <td class="px-4 py-2"><a href="{% url 'recycle_core:weigh_ticket_detail' t.id %}" class="text-blue-700 hover:underline">{{ t.ticket_number|default:t.id }}</a></td>
        <td class="px-4 py-2">{{ t.pickup.customer.name }}</td>
        <td class="px-4 py-2">{{ t.recorded_at }}</td>
        <td class="px-4 py-2">{{ t.net_weight }} {{ t.unit }}</td>
        <td class="px-4 py-2">
          <form method="post" action="{% url 'recycle_core:weigh_ticket_generate_invoice' t.id %}">
            {% csrf_token %}
            <button class="btn-outline">Generate Invoice</button>
          </form>
        </td>
      </tr>
      {% empty %}
      <tr><td class="px-4 py-4 text-center text-gray-500" colspan="5">No tickets.</td></tr>
      {% endfor %}
    </tbody>
  </table>
  {% include 'admin_frontend/_pagination.html' %}
</div>
{% endblock %}
