{% load i18n %}
{# Reusable stockrooms table for any section. Price-rule column/edit for hulls+modules. #}
<div class="d-flex justify-content-between align-items-center mt-4 mb-2">
    <h4 class="m-0">{% trans "Stockrooms" %}</h4>
    <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addStockroomModal">
        <i class="fa-solid fa-plus me-1"></i>{% trans "Add stockroom" %}
    </button>
</div>
<table class="table table-striped align-middle">
    <thead><tr>
        <th>{% if shop.shop_type == 'corporation' %}{% trans "Corporation" %}{% else %}{% trans "Character" %}{% endif %}</th><th>{% if shop.shop_type == 'corporation' %}{% trans "Division" %}{% else %}{% trans "Station" %}{% endif %}</th>
        {% if section != 'fitted' %}<th>{% trans "Container" %}</th>{% endif %}
        {% if section == 'hulls' or section == 'modules' %}<th>{% trans "Default price" %}</th>{% endif %}
        {% if section == 'fitted' %}<th>{% trans "Filter" %}</th>{% endif %}
        <th></th>
    </tr></thead>
    <tbody>
    {% for s in sources %}
        <tr>
            <td>{{ s.owner_display }}</td>
            <td>{{ s.location_display }}</td>
            {% if section != 'fitted' %}
            <td>{% if s.container_name %}{{ s.container_name }}{% elif s.container_item_id %}#{{ s.container_item_id }}{% else %}<span class="text-muted">{% trans "Whole station" %}</span>{% endif %}</td>
            {% endif %}
            {% if section == 'hulls' or section == 'modules' %}
            <td><span class="badge bg-secondary">{{ s.price_rule_display }}</span></td>
            {% endif %}
            {% if section == 'fitted' %}
            <td>{% if s.name_filter %}<code>{{ s.name_filter }}</code>{% else %}<span class="text-muted">{% trans "All ships" %}</span>{% endif %}</td>
            {% endif %}
            <td class="text-end">
                {% if section == 'hulls' or section == 'modules' %}
                <button type="button" class="btn btn-sm btn-outline-theme edit-sr-btn"
                        data-url="{% url 'backoffice:edit_stockroom' shop.pk s.pk %}"
                        data-price-mode="{{ s.price_mode }}"
                        data-price-pct="{{ s.price_pct|default_if_none:'' }}">
                    <i class="fa-solid fa-pen-to-square fa-fw"></i> {% trans "Edit" %}
                </button>
                {% endif %}
                {% if section == 'fitted' %}
                <button type="button" class="btn btn-sm btn-outline-theme edit-sr-btn"
                        data-url="{% url 'backoffice:edit_stockroom' shop.pk s.pk %}"
                        data-name-filter="{{ s.name_filter }}"
                        data-strip-marker="{{ s.strip_marker|yesno:'1,' }}">
                    <i class="fa-solid fa-pen-to-square fa-fw"></i> {% trans "Edit" %}
                </button>
                {% endif %}
                <form method="post" action="{% url 'backoffice:remove_stockroom' shop.pk s.pk %}" class="d-inline">
                    {% csrf_token %}
                    <button class="btn btn-sm btn-outline-danger">{% trans "Remove" %}</button>
                </form>
            </td>
        </tr>
    {% empty %}
        <tr><td colspan="{% if section == 'hulls' or section == 'modules' %}5{% elif section == 'fitted' %}4{% else %}4{% endif %}" class="text-muted">{% trans "No stockrooms yet." %}</td></tr>
    {% endfor %}
    </tbody>
</table>
