{% extends "base.html" %}
{% block title %}Delivery Tracking{% endblock %}
{% block content %}
<div class="container-fluid">
  <h2>🚚 Delivery Tracking</h2>
  <form method="get" class="row g-2 mb-3">
    <div class="col-md-4"><input class="form-control" name="q" value="{{ q }}" placeholder="Invoice / order / phone / tracking / item"></div>
    <div class="col-md-3"><select class="form-select" name="status"><option>All</option>{% for s in statuses %}<option value="{{s}}" {% if status_filter==s %}selected{% endif %}>{{s}}</option>{% endfor %}</select></div>
    <div class="col-md-2"><button class="btn btn-primary w-100">Filter</button></div>
  </form>
  <div class="table-responsive"><table class="table table-striped table-hover align-middle"><thead><tr><th>Invoice</th><th>Item</th><th>Customer</th><th>Courier</th><th>Tracking</th><th>Status</th><th>Update</th></tr></thead><tbody>
  {% for o in orders %}
  <tr><form method="post"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="order_id" value="{{ o.id }}">
    <td>{{ o.invoice_no or o.order_id }}</td><td>{{ o.item_name }}</td><td>{{ o.contact1 }}</td>
    <td><input class="form-control form-control-sm" name="delivery_courier" value="{{ o.delivery_courier or '' }}"></td>
    <td><input class="form-control form-control-sm" name="tracking_no" value="{{ o.tracking_no or '' }}"></td>
    <td><select class="form-select form-select-sm" name="delivery_status">{% for s in statuses %}<option value="{{s}}" {% if (o.delivery_status or 'Pending')==s %}selected{% endif %}>{{s}}</option>{% endfor %}</select></td>
    <td><button class="btn btn-success btn-sm">Save</button></td>
  </form></tr>{% else %}<tr><td colspan="7" class="text-center">No orders found.</td></tr>{% endfor %}
  </tbody></table></div>
</div>
{% endblock %}
