{% extends "base.html" %}
{% load static %}

{% block title %}{{ area.name }}{% endblock %}

{% block header_bar %}
    <a href="{{ area.container_url }}"><img class="icon" src="{% static "inventory/img/back.svg" %}"></a>
    {{ area.name }}
    <span class="small">{{ area.description}}</span>
{% endblock %}

{% block header_icons %}
    {% if user.is_staff %}
        <li>
            <a href="{% url "admin:inventory_area_change" object_id=area.pk %}"><img class="icon" src="{% static "inventory/img/edit.svg" %}"></a>
        </li>
        {% include 'inventory/set_index.html' with item=area is_index=is_index %}
    {% endif %}
{% endblock %}

{% block content %}

    {% if area.show_sub_area %}
        <h3>Areas</h3>

        <table class="list">
            <tbody>
            {% for a in area.area_related.all %}
                <tr>
                    <td>
                        <a href="{% url 'area-detail' a.id %}" title="{{ a.description }}">{{ a.name }}</a>
                    </td>
                    <td>
                    {% if user.is_staff %}
                        <a class="edit" href="{% url "admin:inventory_area_change" object_id=a.pk %}"><img class="icon" src="{% static 'inventory/img/edit.svg' %}"></a>
                    {% endif %}
                    </td>
                </tr>
            {% empty %}
                <tr><td>No areas defined</td></tr>
            {% endfor %}
            </tbody>
        </table>
    
        {% if user.is_staff %}
            <p><a href="{% url "admin:inventory_area_add" %}?container={{ area.id }}&index=0">Create new area...</a></p>
        {% endif %}
    {% endif %}

    <h3>Containers</h3>

    <table class="list">
        <tbody>
        {% for box in area.box_related.all %}
            <tr>
                <td>
                    <a href="{% url 'box-detail' box.id %}" title="{{ box.description }}">{{ box.name }}</a>
                </td>
                <td>
                {% if user.is_staff %}
                    <a class="edit" href="{% url "admin:inventory_box_change" object_id=box.pk %}"><img class="icon" src="{% static 'inventory/img/edit.svg' %}"></a>
                {% endif %}
                </td>
            </tr>
        {% empty %}
            <tr><td>No containers defined</td></tr>
        {% endfor %}
        </tbody>
    </table>

    {% if user.is_staff %}
        <p><a href="{% url "admin:inventory_box_add" %}?container={{ area.id }}&index=0">Create new container...</a></p>
    {% endif %}
{% endblock %}