{% extends base_template %}
{% load debusine %}
{% block content %}
    <h1>
        <span class="bi bi-hammer" title="Work request"></span>
        {{ title }}
    </h1>
    {% if specialized_view_path %}
        <p>
            <a href="{{ specialized_view_path }}">{{ work_request.task_name }} view</a>
        </p>
    {% endif %}
    {% if work_request.is_workflow or work_request.is_part_of_workflow %}
        <h2>Workflow information</h2>
        <ul>
            {% with work_request_root=work_request.get_workflow_root %}
                {% if work_request_root != work_request %}
                    <li>
                        Root: <a href="{% url "work_requests:detail" pk=work_request_root.id %}">{{ work_request_root.workflow_display_name }}</a>
                    </li>
                {% endif %}
            {% endwith %}
            {% if work_request.parent %}
                <li>
                    Parent: <a href="{% url "work_requests:detail" pk=work_request.parent.id %}">{{ work_request.parent.workflow_display_name }}</a>
                </li>
            {% endif %}
            {% if work_request.children.all %}
                <li>{% include "web/_work_request-descendants.html" %}</li>
            {% endif %}
        </ul>
        {% if perms.db.change_workrequest and work_request.can_be_unblocked and work_request.unblock_strategy == "manual" %}
            <div class="card mb-2">
                <div class="card-header">Review blocked workflow step</div>
                <div class="card-body">
                    {% if manual_unblock_log_entries %}
                        {% include "web/_manual_unblock_log.html" with manual_unblock_log_entries=manual_unblock_log_entries only %}
                    {% endif %}
                    <form id="manual-unblock-form"
                          method="post"
                          action="{% url "work_requests:unblock" pk=work_request.id %}">
                        {% csrf_token %}
                        {{ manual_unblock_form.as_p }}
                        <input class="btn btn-success btn-sm"
                               type="submit"
                               name="action"
                               value="Accept">
                        <input class="btn btn-danger btn-sm"
                               type="submit"
                               name="action"
                               value="Reject">
                        <input class="btn btn-info btn-sm"
                               type="submit"
                               name="action"
                               value="Record notes only">
                    </form>
                </div>
            </div>
        {% endif %}
    {% endif %}
    {% if work_request.requires_signature and user == work_request.created_by %}
        <div id="requires-signature" class="card mb-2">
            <div class="card-header">Waiting for signature</div>
            <div class="card-body">
                Run <code>debusine provide-signature {{ work_request.id }}</code> to sign this request.
            </div>
        </div>
    {% endif %}
    {% if validation_error %}
        <h2>Validation error</h2>
        <pre><code>{{ validation_error }}</code></pre>
    {% endif %}
    <div id="metadata" class="card mb-2">
        <div class="card-header">Metadata</div>
        <div class="card-body text-white bg-dark">{{ task_data }}</div>
    </div>
    <table id="artifacts" class="table table-sm wr-artifacts">
        <thead>
            <tr>
                <th></th>
                <th>Type</th>
                <th>Name</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th title="Input artifacts"
                    rowspan="{{ source_artifacts|length|add:"1" }}">
                    <span class="bi bi-box-arrow-in-down-right"></span>
                </th>
            </tr>
            {% if source_artifacts %}
                {% include "web/_artifact-list.html" with artifacts=source_artifacts only %}
            {% elif source_artifacts_not_implemented %}
                <tr>
                    <td colspan="4">Listing source artifacts not yet implemented for this task type</td>
                </tr>
            {% else %}
                <tr>
                    <td colspan="4">No input artifacts</td>
                </tr>
            {% endif %}
        </tbody>
        <tbody>
            <tr>
                <th title="Output artifacts"
                    rowspan="{{ built_artifacts|length|add:"1" }}">
                    <span class="bi bi-box-arrow-down-right"></span>
                </th>
            </tr>
            {% if built_artifacts %}
                {% include "web/_artifact-list.html" with artifacts=built_artifacts only %}
            {% else %}
                <tr>
                    <td colspan="4">No artifacts produced</td>
                </tr>
            {% endif %}
        </tbody>
    </table>
{% endblock %}
