{% extends "base.html" %}
{% block title %}Stock Locations{% endblock %}
{% block content %}
<div class="space-y-4">
  <div class="flex justify-between items-center">
    <h1 class="text-2xl font-bold">Stock Locations</h1>
    <div class="flex gap-2">
      <a href="{% url 'inventory:branch_list' %}" class="btn btn-outline btn-sm">Branches</a>
      <a href="{% url 'inventory:location_create' %}" class="btn btn-primary btn-sm">New Location</a>
    </div>
  </div>
  <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:location_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>Name</th><th>Branch</th><th>Code</th><th>Status</th><th>Description</th></tr></thead>
        <tbody>
          {% for location in locations %}
          <tr>
            <td>{{ location.name }}</td>
            <td>{{ location.branch.name|default:"-" }}</td>
            <td>{{ location.code|default:"-" }}</td>
            <td>{% if location.is_active %}Active{% else %}Inactive{% endif %}</td>
            <td>{{ location.description|default:"-" }}</td>
          </tr>
          {% empty %}
          <tr><td colspan="5" class="text-center opacity-70">No locations.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endblock %}
