{% 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>
                            <a href="{% url "artifacts:detail-file" artifact_id=artifact.id file_in_artifact_id=fileinartifact.id path=fileinartifact.path %}">{{ fileinartifact.basename }}</a>
                        </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 artifact.relations.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 relation in artifact.relations.all %}
                    <tr>
                        <td>{{ relation.type }}</td>
                        <td>
                            <i class="bi bi-arrow-right"></i>
                        </td>
                        {% include "web/_artifact-list-row.html" with artifact=relation.target %}
                    </tr>
                {% endfor %}
                {% for relation in reverse_extends %}
                    <tr>
                        <td>{{ relation.type }}</td>
                        <td>
                            <i class="bi bi-arrow-left"></i>
                        </td>
                        {% include "web/_artifact-list-row.html" with artifact=relation.artifact %}
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
    <br>
{% endblock %}
