{% extends "base.html" %}
{% block title %}Stock Transfers{% endblock %}
{% block content %}
<div class="space-y-4">
  <div class="flex justify-between items-center">
    <h1 class="text-2xl font-bold">Stock Transfers</h1>
    <a href="{% url 'inventory:transfer_create' %}" class="btn btn-primary btn-sm">New Transfer</a>
  </div>
  <form method="get" class="flex flex-wrap gap-2 items-end">
    <label class="form-control w-52">
      <span class="label-text">Status</span>
      <select name="status" class="select select-bordered">
        <option value="">All Statuses</option>
        <option value="requested" {% if current_status == 'requested' %}selected{% endif %}>Requested</option>
        <option value="approved" {% if current_status == 'approved' %}selected{% endif %}>Approved</option>
        <option value="rejected" {% if current_status == 'rejected' %}selected{% endif %}>Rejected</option>
        <option value="completed" {% if current_status == 'completed' %}selected{% endif %}>Completed</option>
      </select>
    </label>
    <label class="form-control w-64">
      <span class="label-text">Branch</span>
      <select name="branch" class="select select-bordered">
        <option value="">All Branches</option>
        {% for branch in branches %}
          <option value="{{ branch.id }}" {% if current_branch == branch.id|stringformat:"s" %}selected{% endif %}>{{ branch.name }}</option>
        {% endfor %}
      </select>
    </label>
    <button class="btn btn-primary btn-sm">Filter</button>
    {% if current_status or current_branch %}
      <a href="{% url 'inventory:transfer_list' %}" class="btn btn-ghost btn-sm">Clear</a>
    {% endif %}
  </form>
  <div class="card bg-base-100 border border-base-200">
    <div class="overflow-x-auto">
      <table class="table table-zebra">
        <thead><tr><th>Reference</th><th>From</th><th>To</th><th>Status</th><th>Requested By</th><th></th></tr></thead>
        <tbody>
          {% for transfer in transfers %}
          <tr>
            <td>{{ transfer.reference }}</td>
            <td>{{ transfer.from_location }} <span class="opacity-60">({{ transfer.from_location.branch.name|default:"-" }})</span></td>
            <td>{{ transfer.to_location }} <span class="opacity-60">({{ transfer.to_location.branch.name|default:"-" }})</span></td>
            <td>{{ transfer.get_status_display }}</td>
            <td>{{ transfer.requested_by|default:"-" }}</td>
            <td><a class="btn btn-ghost btn-xs" href="{% url 'inventory:transfer_detail' transfer.pk %}">View</a></td>
          </tr>
          {% empty %}
          <tr><td colspan="6" class="text-center opacity-70">No transfers.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  {% include "partials/pagination.html" with page_obj=transfers %}
</div>
{% endblock %}
