{% extends base_template %}
{% load debusine %}
{% block navbar_left %}
    {{ block.super }}
    {% include "web/_collection-menu.html" with collection=collection only %}
{% endblock %}
{% block title %}Collection {{ collection.name }}@{{ collection.category }}{% endblock %}
{% block content %}
    {% ui collection as coll %}
    <h2>Details</h2>
    <table class="table table-hover table-striped" id="collection-details-table">
        <tbody>
            <tr>
                <th>Full history retention period (days)</th>
                <td>
                    {% if collection.full_history_retention_period is None %}
                        Always
                    {% else %}
                        {{ collection.full_history_retention_period.days }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <th>Metadata only retention period (days)</th>
                <td>
                    {% if collection.metadata_only_retention_period is None %}
                        Always
                    {% else %}
                        {{ collection.metadata_only_retention_period.days }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <th>Retains artifacts</th>
                <td>{{ collection.get_retains_artifacts_display }}</td>
            </tr>
            {% if collection.workflow %}
                <tr>
                    <th>Workflow</th>
                    <td>
                        <a href="{{ collection.workflow.get_absolute_url }}">{{ collection.workflow }}</a>
                    </td>
                </tr>
            {% endif %}
            {% if suite_based_on %}
                <tr>
                    <th>Based on</th>
                    <td>
                        <a id="suite-based-on" href="{{ suite_based_on.get_absolute_url }}">{{ suite_based_on }}</a>
                    </td>
                </tr>
            {% endif %}
        </tbody>
    </table>
    {% if data %}
        <div id="metadata" class="card mb-2">
            <div class="card-header">Metadata</div>
            {% include "web/_card-body.html" with data=data only %}
        </div>
    {% endif %}
    {% if coll.can_configure or coll.can_delete %}
        <div class="btn-group"
             role="group"
             aria-label="Collection actions"
             id="collection-actions">
            {% if coll.can_configure %}
                {{ coll.place_update.as_button }}
                {{ coll.place_collection_relation_configure.as_button }}
            {% endif %}
            {% if coll.can_delete %}{{ coll.place_delete.as_button }}{% endif %}
        </div>
    {% endif %}
    <h2 class="mt-4">Contents</h2>
    {% if not collections and not artifacts and not bare %}
        <p>The collection is empty</p>
    {% else %}
        <p>{% place coll search as_button label="Search" %}</p>
    {% endif %}
    {% if collections %}
        <h3 class="mt-4">Collections</h3>
        <table class="table table-sm table-hover table-striped">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Category</th>
                    <th>Collection name</th>
                </tr>
            </thead>
            <tbody>
                {% for i in collections %}
                    <tr>
                        <th>
                            <a href="{{ i.get_absolute_url }}">{{ i.name }}</a>
                        </th>
                        <th>{{ i.collection.category }}</th>
                        <td>
                            <a href="{{ i.collection.get_absolute_url }}">{{ i.collection.name }}</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
    {% if artifacts %}
        <h3 class="mt-4">Artifacts</h3>
        <table class="table table-sm table-hover table-striped">
            <thead>
                <tr>
                    <th>Category</th>
                    <th>Count current</th>
                    <th>Count historical</th>
                </tr>
            </thead>
            <tbody>
                {% for a in artifacts %}
                    <tr>
                        <th>
                            <a href="{% url 'workspaces:collections:search' wname=collection.workspace.name cname=collection.name ccat=collection.category %}?category={{ a.category }}">{{ a.category }}</a>
                        </th>
                        <td>{{ a.count }}</td>
                        <td>{{ a.count_removed }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
    {% if bare %}
        <h3 class="mt-4">Bare data</h3>
        <table id="stats-bare-data" class="table table-sm table-hover table-striped">
            <thead>
                <tr>
                    <th>Category</th>
                    <th>Count current</th>
                    <th>Count historical</th>
                </tr>
            </thead>
            <tbody>
                {% for i in bare %}
                    <tr>
                        <th>
                            <a href="{% url 'workspaces:collections:search' wname=collection.workspace.name cname=collection.name ccat=collection.category %}?category={{ i.category }}">{{ i.category }}</a>
                        </th>
                        <td>{{ i.count }}</td>
                        <td>{{ i.count_removed }}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
{% endblock %}
