{% extends "web/_base_rightbar.html" %}
{% load artifacts %}
{% load debusine %}
{% block content %}
    <h1 class="mb-4" title="{{ artifact.category }}">
        <span class="bi bi-{{ artifact|artifact_icon_name }}"></span>
        Artifact {{ artifact_label }}
    </h1>
    <div id="metadata" class="card">
        <div class="card-header">Metadata</div>
        <div class="card-body text-white bg-dark">{{ artifact_data }}</div>
    </div>
    {% if file %}
        <h2>File</h2>
        {% widget file %}
    {% elif file_list %}
        <h2>Files</h2>
        <table id="file-list" class="table table-sm">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Size (bytes)</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for fileinartifact in file_list %}
                    <tr>
                        <td>
                            {% if fileinartifact.complete %}
                                <a href="{{ fileinartifact.get_absolute_url }}">{{ fileinartifact.basename }}</a>
                            {% else %}
                                {{ fileinartifact.basename }} (incomplete)
                            {% endif %}
                        </td>
                        <td title="{{ fileinartifact.file.size }}">{{ fileinartifact.file.size|filesizeformat }}</td>
                        <td>
                            <div class="btn-group btn-group-sm" role="toolbar" aria-label="Shortcuts">
                                {% ui_shortcuts fileinartifact as shortcuts %}
                                {% for shortcut in shortcuts %}
                                    {% widget shortcut %}
                                {% endfor %}
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <h2>Files</h2>
        <p id="no-files">The artifact does not have any files.</p>
    {% endif %}
    {% if forward.exists or reverse_extends.exists %}
        <h2>Relations</h2>
        <table id="relation-list" class="table table-sm">
            <thead>
                <tr>
                    <th>Relation</th>
                    <th>Direction</th>
                    <th>Type</th>
                    <th>Name</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for related in forward.all %}
                    <tr>
                        <td>{{ related.relation_type }}</td>
                        <td>
                            <i class="bi {% icon "artifact_relation_target" %}"></i>
                        </td>
                        {% include "web/_artifact-list-row.html" with artifact=related %}
                    </tr>
                {% endfor %}
                {% for related in reverse_extends %}
                    <tr>
                        <td>{{ related.relation_type }}</td>
                        <td>
                            <i class="bi {% icon "artifact_relation_source" %}"></i>
                        </td>
                        {% include "web/_artifact-list-row.html" with artifact=related %}
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
    <br>
{% endblock %}
