{% extends base_template %}
{% load debusine %}
{% block navbar_left %}
    {{ block.super }}
    {% include "web/_collection-menu.html" with collection=collection only %}
{% endblock %}
{% block content %}
    {% if relation_type %}
        <p id="relations-of-type">
            Relations of type "{{ relation_type_label }}" only. <a href="{% url "workspaces:collections:collection_relations:list" wname=collection.workspace.name ccat=collection.category cname=collection.name %}">List</a> all.
        </p>
    {% endif %}
    <div class="row">
        <div class="col-8">
            <table class="table table-sm table-hover table-striped table-tds-vertical-align-middle"
                   id="relations">
                <thead>
                    <tr>
                        <th>Type</th>
                        <th>Target</th>
                        <th>Position</th>
                        <th>Details</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for collection_relation in collection_relations %}
                        <tr>
                            <td>{{ collection_relation.get_type_display }}</td>
                            <td>
                                <a href="{{ collection_relation.target.get_absolute_url }}">{{ collection_relation.target }}</a>
                            </td>
                            <td>{{ collection_relation.position|default_if_none:"" }}</td>
                            <td>{% include "web/_collection_relation-details.html" with collection_relation=collection_relation only %}</td>
                            <td>
                                {% ui collection_relation as collection_relation_ui %}
                                {% for shortcut in collection_relation_ui.ui_shortcuts %}
                                    {% widget shortcut %}
                                {% endfor %}
                            </td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="5" id="no-relations">
                                {% if relation_type %}
                                    Collection <code>{{ collection }}</code> does not have any relations of type <code>{{ relation_type }}</code>.
                                    <br>
                                    <a href="{% url "workspaces:collections:collection_relations:list" wname=collection.workspace.name ccat=collection.category cname=collection.name %}">List all relations</a> for <code>{{ collection }}</code>
                                {% else %}
                                    Collection <code>{{ collection }}</code> does not have any relations.
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% if show_create %}
                <a id="create"
                   href="{% url "workspaces:collections:collection_relations:create" wname=collection.workspace.name ccat=collection.category cname=collection.name %}"
                   class="btn btn-primary">Create</a>
            {% endif %}
            {% if show_reorder_requires %}
                <a id="show_reorder_requires"
                   href="{% url "workspaces:collections:collection_relations:reorder_requires" wname=collection.workspace.name ccat=collection.category cname=collection.name %}"
                   class="btn btn-primary">Re-order Requires</a>
            {% endif %}
        </div>
    </div>
{% endblock %}
