{% extends base_template %}
{% load debusine %}
{% block content %}
    {% ui workspace as ws %}
    <h2>Details</h2>
    <table class="table table-hover table-striped" id="workspace-details">
        <tbody>
            <tr id="workspace-details-public">
                <th>Public</th>
                <td>{{ workspace.public|yesno:"Yes,No" }}</td>
            </tr>
            <tr id="workspace-details-expiration">
                <th>Expires</th>
                <td>
                    {% if workspace.expiration_delay %}
                        {{ workspace.expire_at|date:"Y-m-d" }}
                    {% else %}
                        Never
                    {% endif %}
                </td>
            </tr>
            <tr id="workspace-details-default-expiration">
                <th>Default expiration delay {% help "expiration_delay" %} (days)</th>
                <td>{{ workspace.default_expiration_delay.days|default:"Never" }}</td>
            </tr>
            {% if parents %}
                <tr id="workspace-details-parents">
                    <th>Inherits from</th>
                    <td>
                        {% spaceless %}
                            {# Try hard not to have djlint insert unwanted spaces #}
                            {% for w in parents %}
                                <a href="{{ w.get_absolute_url }}">{{ w }}</a>
                                {% if not forloop.last %}<span>,&#x0020;</span>{% endif %}
                            {% endfor %}
                        {% endspaceless %}
                    </td>
                </tr>
            {% endif %}
            {% if deb_archive_url %}
                <tr id="workspace-debian-archive">
                    <th>Debian archive</th>
                    <td>
                        <a href="{{ deb_archive_url }}">{{ deb_archive_url }}</a>
                    </td>
                </tr>
            {% endif %}
        </tbody>
    </table>
    {% if ws.can_configure or ws.can_create_collections %}
        <div class="btn-group"
             role="group"
             aria-label="Workspace actions"
             id="workspace-actions">
            {% if ws.can_configure %}
                {{ ws.place_update.as_button }}
                {{ ws.place_update_inheritance.as_button }}
            {% endif %}
            {% if ws.can_create_collections %}{{ ws.place_collection_create.as_button }}{% endif %}
        </div>
    {% endif %}
    <h2 class="mt-4">Workflow templates</h2>
    <div id="workflow-templates">
        {% if workflow_templates %}
            <style>
    #workflow-templates-list th:nth-last-child(-n+3),
    #workflow-templates-list td:nth-last-child(-n+3) {
        width: 1%;
        white-space: nowrap; /* Prevent wrapping */
    }
            </style>
            <table class="table table-hover table-striped" id="workflow-templates-list">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Task name</th>
                        <th>
                            <span title="Running workflows" class="badge text-bg-info">R</span>
                        </th>
                        <th>
                            <span title="Input needed workflows" class="badge text-bg-secondary">I</span>
                        </th>
                        <th>
                            <span title="Completed workflows" class="badge text-bg-primary">C</span>
                        </th>
                    </thead>
                    <tbody>
                        {% for t in workflow_templates %}
                            {% ui t as t_ui %}
                            <tr>
                                <td>
                                    <a href="{{ t.get_absolute_url }}">{{ t.name }}</a>
                                </td>
                                <td>
                                    <a href="{{ t_ui.get_help_url }}">{{ t.task_name }}</a>
                                </td>
                                <td>
                                    <a href="{% url "workspaces:workflows:list" wname=workspace.name %}?filter-statuses=running__any&amp;filter-workflow_templates={{ t.name }}">{{ t.running_workflows }}</a>
                                </td>
                                <td>
                                    <a href="{% url "workspaces:workflows:list" wname=workspace.name %}?filter-statuses=running__needs_input&amp;filter-workflow_templates={{ t.name }}">{{ t.needs_input_workflows }}</a>
                                </td>
                                <td>
                                    <a href="{% url "workspaces:workflows:list" wname=workspace.name %}?filter-statuses=completed&amp;filter-workflow_templates={{ t.name }}">{{ t.completed_workflows }}</a>
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            {% else %}
                No workflow templates configured for this workspace.
            {% endif %}
        </div>
        {% if collection_stats %}
            <h2>Collections</h2>
            <table class="table table-hover table-striped">
                <thead>
                    <tr>
                        <th>Category</th>
                        <th>Count</th>
                    </tr>
                </thead>
                <tbody>
                    {% for s in collection_stats %}
                        <tr>
                            <td>
                                <a href="{% url 'workspaces:collections:category_list' wname=workspace.name ccat=s.category %}">{{ s.category }}</a>
                            </td>
                            <td>{{ s.count }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td>
                            <a href="{% url 'workspaces:collections:list' wname=workspace.name %}">All collections</a>
                        </td>
                        <td>{{ collection_count }}</td>
                    </tr>
                </tfoot>
            </table>
        {% endif %}
    {% endblock %}
