{% extends "web/_base_unscoped.html" %}
{% load static %}
{% load debusine %}
{# Disable the "Debusine" string next to the homepage icon #}
{% block navbar_brand_name %}{% endblock %}
{# Implement a navigation bar with scope / workspace / etc. #}
{% block navbar_left %}
    {% ui scope as scopeui %}
    <li class="nav-item">{{ scopeui.place.as_nav }}</li>
    {% if workspace %}
        {% ui workspace as workspaceui %}
        {% if other_workspaces %}
            <li class="nav-item dropdown" id="nav-workspaces">
                <div class="btn-group">
                    {{ workspaceui.place.as_nav }}
                    <a class="nav-link btn btn-light dropdown-toggle dropdown-toggle-split"
                       href="#"
                       role="button"
                       data-bs-toggle="dropdown"
                       aria-expanded="false">
                        <span class="visually-hidden">Toggle Dropdown</span>
                    </a>
                    <ul class="dropdown-menu">
                        {% for other_workspace in other_workspaces %}
                            <li>
                                <a class="dropdown-item" href="{{ other_workspace.get_absolute_url }}">{{ other_workspace.name }}</a>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            </li>
        {% else %}
            <li class="nav-item" id="nav-workspaces">
                <a class="nav-link btn btn-light"
                   href="{{ workspace.get_absolute_url }}">
                    <span class="bi {% icon "workspace" %}"></span> {{ workspace.name }}</a>
            </li>
        {% endif %}
        <li class="nav-item">
            <a class="nav-link btn btn-light"
               href="{% url "workspaces:work-requests:list" wname=workspace.name %}"><span class="bi {% icon "work_request" %}"></span> Work requests</a>
        </li>
        <li class="nav-item" id="nav-workflows">
            {% if workflow_templates %}
                <div class="btn-group">
                    <a class="nav-link btn btn-light"
                       href="{% url "workspaces:workflows:list" wname=workspace.name %}"><span class="bi {% icon "workflow" %}"></span> Workflows</a>
                    <a class="nav-link btn btn-light dropdown-toggle dropdown-toggle-split"
                       href="#"
                       role="button"
                       data-bs-toggle="dropdown"
                       aria-expanded="false">
                        <span class="visually-hidden">Toggle Dropdown</span>
                    </a>
                    <ul class="dropdown-menu">
                        {% for workflow_template in workflow_templates %}
                            <li>
                                <a class="dropdown-item"
                                   href="{% url "workspaces:workflows:list" wname=workspace.name %}?filter-workflow_templates={{ workflow_template.name }}">{{ workflow_template.name }}</a>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            {% else %}
                <a class="nav-link btn btn-light"
                   href="{% url "workspaces:workflows:list" wname=workspace.name %}"><span class="bi {% icon "workflow" %}"></span> Workflows</a>
            {% endif %}
        </li>
        <li class="nav-item dropdown" id="nav-collections">
            <div class="btn-group">
                <a class="nav-link btn btn-light"
                   href="{% url "workspaces:collections:list" wname=workspace.name %}"><span class="bi {% icon "collections" %}"></span> Collections</a>
                <a class="nav-link btn btn-light dropdown-toggle dropdown-toggle-split"
                   href="#"
                   role="button"
                   data-bs-toggle="dropdown"
                   aria-expanded="false">
                    <span class="visually-hidden">Toggle Dropdown</span>
                </a>
                <ul class="dropdown-menu">
                    {% for collection in workspace_collections %}
                        <li>
                            <a class="dropdown-item" href="{{ collection.get_absolute_url }}">{{ collection }}</a>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link btn btn-light dropdown-toggle"
               href="#"
               id="navbar-plumbing-actions"
               role="button"
               data-bs-toggle="dropdown"
               aria-expanded="false">Plumbing</a>
            <ul class="dropdown-menu">
                {% if workspace and workspace|has_perm:"can_create_artifacts" %}
                    <li>
                        <a id="nav-create-artifact"
                           class="dropdown-item"
                           href="{% url "workspaces:artifacts:create" wname=workspace.name %}">Create artifact</a>
                    </li>
                {% endif %}
                {% if workspace and workspace|has_perm:"can_create_work_requests" %}
                    <li>
                        <a id="nav-create-work-request"
                           class="dropdown-item"
                           href="{% url "workspaces:work-requests:create" wname=workspace.name %}">Create work request</a>
                    </li>
                {% endif %}
                <li>
                    <a id="nav-task-configuration-inspector"
                       class="dropdown-item"
                       href="{% url "workspaces:task_configuration_inspector" wname=workspace.name %}">Task configuration inspector</a>
                </li>
            </ul>
        </li>
    {% endif %}
{% endblock %}
