{% extends "base.html" %}
{% block title %}Stock Movement History{% endblock %}
{% block content %}
<div class="space-y-4">
  <h1 class="text-2xl font-bold">Stock Movement History</h1>
  <form method="get" class="flex flex-wrap gap-2 items-end">
    <label class="form-control">
      <span class="label-text">Search</span>
      <input type="text" name="q" value="{{ query }}" class="input input-bordered" placeholder="Product/reference/note" />
    </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">Search</button>
    {% if query or current_branch %}
      <a href="{% url 'inventory:stock_movement_report' %}" class="btn btn-ghost">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>Date</th><th>Product</th><th>Type</th><th>Qty</th><th>Branch</th><th>Location</th><th>Reference</th><th>By</th></tr></thead>
        <tbody>
          {% for move in movements %}
          <tr>
            <td>{{ move.date }}</td>
            <td>{{ move.product }}</td>
            <td>{{ move.get_movement_type_display }}</td>
            <td>{{ move.quantity }}</td>
            <td>{{ move.location.branch.name|default:"-" }}</td>
            <td>{{ move.location|default:"-" }}</td>
            <td>{{ move.reference|default:"-" }}</td>
            <td>{{ move.created_by|default:"-" }}</td>
          </tr>
          {% empty %}
          <tr><td colspan="8" class="text-center opacity-70">No movements found.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  {% include "partials/pagination.html" with page_obj=movements %}
</div>
{% endblock %}
