{#
/**
 * 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 ots-topbar">
    <li class="nav-item">
        <a class="nav-link" href="{{ url_for("home") }}">
            <span class="ots-topbar-icon fa fa-home" aria-hidden="true"></span>
            {% 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">
                <span class="ots-topbar-icon fa fa-calendar" aria-hidden="true"></span>
                {% trans "Schedule" %} <span class="caret" aria-hidden="true"></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") }}">
                        <span class="ots-topbar-icon fa fa-calendar" aria-hidden="true"></span>
                        {% trans "Schedule" %}
                    </a>
                {% endif %}
                {% if currentUser.featureEnabled("daypart.view") %}
                    <a class="{{ groupElementClass }}" href="{{ url_for("daypart.view") }}">
                        <span class="ots-topbar-icon fa fa-clock" aria-hidden="true"></span>
                        {% 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">
                <span class="ots-topbar-icon fa fa-paint-brush" aria-hidden="true"></span>
                {% trans "Design" %} <span class="caret" aria-hidden="true"></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") }}">
                    <span class="ots-topbar-icon fa fa-bullhorn" aria-hidden="true"></span>
                    {% trans "Campaigns" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("layout.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("layout.view") }}">
                    <span class="ots-topbar-icon fa fa-columns" aria-hidden="true"></span>
                    {% trans "Layouts" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("template.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("template.view") }}">
                    <span class="ots-topbar-icon fa fa-clone" aria-hidden="true"></span>
                    {% trans "Templates" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("resolution.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("resolution.view") }}">
                    <span class="ots-topbar-icon fa fa-expand" aria-hidden="true"></span>
                    {% 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">
                <span class="ots-topbar-icon fa fa-folder-open" aria-hidden="true"></span>
                {% trans "Library" %} <span class="caret" aria-hidden="true"></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") }}">
                    <span class="ots-topbar-icon fa fa-list" aria-hidden="true"></span>
                    {% trans "Playlists" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("library.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("library.view") }}">
                    <span class="ots-topbar-icon fa fa-photo" aria-hidden="true"></span>
                    {% trans "Media" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("dataset.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("dataset.view") }}">
                    <span class="ots-topbar-icon fa fa-database" aria-hidden="true"></span>
                    {% trans "DataSets" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("menuBoard.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("menuBoard.view") }}">
                    <span class="ots-topbar-icon fa fa-th-large" aria-hidden="true"></span>
                    {% 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">
                <span class="ots-topbar-icon fa fa-desktop" aria-hidden="true"></span>
                {% trans "Displays" %} <span class="caret" aria-hidden="true"></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") }}">
                    <span class="ots-topbar-icon fa fa-desktop" aria-hidden="true"></span>
                    {% trans "Displays" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("displaygroup.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("displaygroup.view") }}">
                    <span class="ots-topbar-icon fa fa-object-group" aria-hidden="true"></span>
                    {% trans "Display Groups" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("display.syncView") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("syncgroup.view") }}">
                    <span class="ots-topbar-icon fa fa-link" aria-hidden="true"></span>
                    {% trans "Sync Groups" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("displayprofile.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("displayprofile.view") }}">
                    <span class="ots-topbar-icon fa fa-sliders" aria-hidden="true"></span>
                    {% trans "Display Settings" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("playersoftware.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("playersoftware.view") }}">
                    <span class="ots-topbar-icon fa fa-download" aria-hidden="true"></span>
                    {% trans "Player Versions" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("command.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("command.view") }}">
                    <span class="ots-topbar-icon fa fa-terminal" aria-hidden="true"></span>
                    {% 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">
                <span class="ots-topbar-icon fa fa-cog" aria-hidden="true"></span>
                {% trans "Administration" %} <span class="caret" aria-hidden="true"></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") }}">
                        <span class="ots-topbar-icon fa fa-users" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-users-cog" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-wrench" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-th" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-puzzle-piece" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-exchange" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-tasks" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-tags" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-folder" aria-hidden="true"></span>
                        {% 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") }}">
                        <span class="ots-topbar-icon fa fa-font" aria-hidden="true"></span>
                        {% 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">
                <span class="ots-topbar-icon fa fa-chart-bar" aria-hidden="true"></span>
                {% trans "Reporting" %} <span class="caret" aria-hidden="true"></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") }}">
                    <span class="ots-topbar-icon fa fa-file-alt" aria-hidden="true"></span>
                    {% trans "All Reports" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("report.scheduling") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("reportschedule.view") }}">
                    <span class="ots-topbar-icon fa fa-calendar-alt" aria-hidden="true"></span>
                    {% trans "Report Schedules" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("report.saving") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("savedreport.view") }}">
                    <span class="ots-topbar-icon fa fa-save" aria-hidden="true"></span>
                    {% 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">
                <span class="ots-topbar-icon fa fa-shield-alt" aria-hidden="true"></span>
                {% trans "Advanced" %} <span class="caret" aria-hidden="true"></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") }}">
                    <span class="ots-topbar-icon fa fa-list-alt" aria-hidden="true"></span>
                    {% trans "Log" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("sessions.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("sessions.view") }}">
                    <span class="ots-topbar-icon fa fa-history" aria-hidden="true"></span>
                    {% trans "Sessions" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("auditlog.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("auditlog.view") }}">
                    <span class="ots-topbar-icon fa fa-clipboard-list" aria-hidden="true"></span>
                    {% trans "Audit Trail" %}
                </a>
            {% endif %}

            {% if currentUser.featureEnabled("fault.view") %}
                <a class="{{ groupElementClass }}" href="{{ url_for("fault.view") }}">
                    <span class="ots-topbar-icon fa fa-exclamation-triangle" aria-hidden="true"></span>
                    {% trans "Report Fault" %}
                </a>
            {% endif %}
        {% if countViewable > 1 %}
            </div>
        {% endif %}
        </li>
    {% endif %}

    {% set countViewable = currentUser.featureEnabledCount(["developer.edit"]) %}
    {% if countViewable > 0 %}
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                <span class="ots-topbar-icon fa fa-code" aria-hidden="true"></span>
                {% trans "Developer" %} <span class="caret" aria-hidden="true"></span>
            </a>
            <div class="dropdown-menu">
            {% if currentUser.featureEnabled("developer.edit") %}
                <a class="dropdown-item" href="{{ url_for("developer.templates.view") }}">
                    <span class="ots-topbar-icon fa fa-code-branch" aria-hidden="true"></span>
                    {% trans "Module Templates" %}
                </a>
            {% endif %}
            </div>
        </li>
    {% endif %}
</ul>
