{% extends "base.html" %}
{% block title %}Low Stock Report{% endblock %}
{% block content %}
<div class="space-y-4">
  <h1 class="text-2xl font-bold">Low Stock Report</h1>
  <form method="get" class="flex flex-wrap gap-2 items-end">
    <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_branch %}
      <a href="{% url 'inventory:low_stock_report' %}" 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>Product</th><th>Category</th><th>Stock</th><th>Minimum</th></tr></thead>
        <tbody>
          {% for product in products %}
          <tr>
            <td>{{ product.name }}</td>
            <td>{{ product.category|default:"-" }}</td>
            <td>{% if current_branch %}{{ product.branch_stock|default:0 }}{% else %}{{ product.stock_quantity }}{% endif %}</td>
            <td>{{ product.low_stock_alert }}</td>
          </tr>
          {% empty %}
          <tr><td colspan="4" class="text-center opacity-70">No low stock items.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endblock %}
