{% extends "web/_base.html" %}
{% load debusine %}
{% block content %}
    <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 workspace|has_perm:"can_configure" %}
                <tr id="workspace-details-configure">
                    <td colspan="2">
                        <a class="btn btn-primary"
                           href="{{ workspace.get_absolute_url_configure }}">Configure</a>
                        <a class="btn btn-primary"
                           href="{{ workspace.get_absolute_url_configure_inheritance }}">Configure inheritance</a>
                    </td>
                </tr>
            {% endif %}
        </tbody>
    </table>
    <h2>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-secondary">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 %}
