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

{% block title %}Manufacturer: {{ manufacturer }}{% endblock %}

{% block header_bar %}
    <a href="{% url 'manufacturer-list' %}"><img class="icon" src="{% static "inventory/img/back.svg" %}"></a>
    Manufacturer: {{ manufacturer.name }}
    <span class="small">{{ manufacturer.description }}</span></h2>
{% endblock %}

{% block header_icons %}
    {% if user.is_staff %}
        <li>
            <a href="{% url "admin:inventory_manufacturer_change" object_id=manufacturer.pk %}"><img class="icon" src="{% static "inventory/img/edit.svg" %}"></a>
        </li>
    {% endif %}
{% endblock %}

{% block content %}
    <table class="attribute-list">
        <tbody>
            <tr>
                <th>Name</th>
                <td>{{ manufacturer.name }}</td>
            </tr>
            <tr>
                <th>Description</th>
                <td>{{ manufacturer.description }}</td>
            </tr>
        {% if manufacturer.icon %}
            <tr>
                <th>Icon</th>
                <td><img src="{{ manufacturer.icon.url }}" title="{{ manufacturer.name }}" style="max-height: 20px;"></td>
            </tr>
        {% endif %}
        <tr>
            <th>Link</th>
            <td>{% if manufacturer.web_link %}<a href="{{ manufacturer.web_link }}" title="{{ manufacturer.name }}">{{ manufacturer.web_link }}{% else %}-{% endif %}</td>
        </tr>
        
        <tr>
            <th>Tags</th>
            <td>
                <ul class="tag-list">
                    {% for tag in manufacturer.tags.all %}
                        <li><a href="{% url 'tag-detail' tag.id %}" title="{{ tag.name }}">{{ tag.name }}</a></li>
                    {% empty %}
                        No tags
                    {% endfor %}
                </ul>
            </td>
        </tr>

            <tr><th>Created at</th><td>{{ manufacturer.created_at }}</td></tr>
        {% if manufacturer.created_at != manufacturer.changed_at %}
            <tr><th>Last change</th><td>{{ manufacturer.changed_at }}</td></tr>
        {% endif %}
        </tbody>
    </table>

    <h2>Items</h2>

    {% url 'manufacturer-detail' manufacturer.id as this_url %}
    {% include "inventory/pagination.html" with url=this_url id="paginator_top" param="item" paginator=items %}
    {% include "inventory/item_list.html" with items=items show_distributor=1 %}
    {% include "inventory/pagination.html" with url=this_url id="paginator_bottom" param="item" paginator=items %}

{% endblock %}