{#
/**
 * Copyright (C) 2023 Xibo Signage Ltd
 *
 * Xibo - Digital Signage - https://xibosignage.com
 *
 * This file is part of Xibo.
 *
 * Xibo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Xibo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 */
#}
<ul class="nav navbar-nav">
    <li class="nav-item"><a class="nav-link" href="{{ url_for("home") }}">{% trans "Dashboard" %}</a></li>

    {% set countViewable = currentUser.featureEnabledCount(["schedule.view", "daypart.view"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Schedule" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}
                {% if currentUser.featureEnabled("schedule.view") %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("schedule.view") }}">{% trans "Schedule" %}</a>
                {% endif %}
                {% if currentUser.featureEnabled("daypart.view") %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("daypart.view") }}">{% trans "Dayparting" %}</a>
                {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["campaign.view", "layout.view", "template.view", "resolution.view"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Design" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}
            {% if currentUser.featureEnabled("campaign.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("campaign.view") }}">{% trans "Campaigns" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("layout.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("layout.view") }}">{% trans "Layouts" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("template.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("template.view") }}">{% trans "Templates" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("resolution.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("resolution.view") }}">{% trans "Resolutions" %}</a>
            {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["library.view", "playlist.view", "dataset.view", "menuBoard.view"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Library" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}
            {% if currentUser.featureEnabled("playlist.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("playlist.view") }}">{% trans "Playlists" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("library.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("library.view") }}">{% trans "Media" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("dataset.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("dataset.view") }}">{% trans "DataSets" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("menuBoard.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("menuBoard.view") }}">{% trans "Menu Boards" %}</a>
            {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["displays.view", "displaygroup.view", "displayprofile.view", "playersoftware.view", "command.view"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Displays" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}
            {% if currentUser.featureEnabled("displays.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("display.view") }}">{% trans "Displays" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("displaygroup.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("displaygroup.view") }}">{% trans "Display Groups" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("display.syncView") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("syncgroup.view") }}">{% trans "Sync Groups" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("displayprofile.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("displayprofile.view") }}">{% trans "Display Settings" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("playersoftware.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("playersoftware.view") }}">{% trans "Player Versions" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("command.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("command.view") }}">{% trans "Commands" %}</a>
            {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% if currentUser.featureEnabled("users.view") and (currentUser.isGroupAdmin() or currentUser.isSuperAdmin()) %}
        {% set userMenuViewable = true %}
    {% else %}
        {% set userMenuViewable = false %}
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["usergroup.view", "module.view", "transition.view", "task.view"]) %}
    {% set groupElementClass = (countViewable > 1 or (countViewable == 1 and userMenuViewable)) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 or userMenuViewable %}
        {% if countViewable > 1 or (countViewable == 1 and userMenuViewable) %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Administration" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% endif %}
            {% if userMenuViewable %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("user.view") }}">{% trans "Users" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("usergroup.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("group.view") }}">{% trans "User Groups" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.isSuperAdmin() %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("admin.view") }}">{% trans "Settings" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.isSuperAdmin() %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("application.view") }}">{% trans "Applications" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("module.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("module.view") }}">{% trans "Modules" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("transition.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("transition.view") }}">{% trans "Transitions" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("task.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("task.view") }}">{% trans "Tasks" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("tag.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("tag.view") }}">{% trans "Tags" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.isSuperAdmin() %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("folders.view") }}">{% trans "Folders" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}

            {% if currentUser.featureEnabled("font.view") %}
                {% if countViewable == 0 %}
                <li class="nav-item">
                {% endif %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("font.view") }}">{% trans "Fonts" %}</a>
                {% if countViewable == 0 %}
                </li>
                {% endif %}
            {% endif %}
            {% if countViewable > 1 or (countViewable == 1 and userMenuViewable) %}
            </div>
            {% endif %}
        {% if countViewable > 1 or (countViewable == 1 and userMenuViewable) %}
        </li>
        {% endif %}
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["report.view", "report.scheduling", "report.saving"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Reporting" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}

            {% if currentUser.featureEnabled("report.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("report.view") }}">{% trans "All Reports" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("report.scheduling") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("reportschedule.view") }}">{% trans "Report Schedules" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("report.saving") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("savedreport.view") }}">{% trans "Saved Reports" %}</a>
            {% endif %}

        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["log.view", "sessions.view", "auditlog.view", "fault.view"]) %}
    {% set groupElementClass = (countViewable > 1) ? 'dropdown-item' : 'nav-link' %}
    {% if countViewable > 0 %}
        {% if countViewable > 1 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Advanced" %} <span class="caret"></span></a>
            <div class="dropdown-menu">
        {% else %}
            <li class="nav-item">
        {% endif %}
            {% if currentUser.featureEnabled("log.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("log.view") }}">{% trans "Log" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("sessions.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("sessions.view") }}">{% trans "Sessions" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("auditlog.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("auditlog.view") }}">{% trans "Audit Trail" %}</a>
            {% endif %}

            {% if currentUser.featureEnabled("fault.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("fault.view") }}">{% trans "Report Fault" %}</a>
            {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}
</ul>