{% macro main_navigation() %}

    {# Prepare #}
    {% set isSite = global.location.site and not global.location.entityCategory %}
    {% set isCategory = global.location.entityCategory and not global.location.entity %}

    {# Render #}
    <div class="ui left fixed vertical inverted main-navigation menu">
        <h1 class="project">entoj</h1>
        <div class="items">
            <div class="item active"><i class="sitemap icon"></i>Sites
                <div class="menu">
                    {% for site in global.sites.getItems() %}
                        <a href="{{ global.urls.resolveSite(site) }}" class="item {% if site and site.isEqualTo(global.location.site) %}active{% endif %}">
                            {{ site.name }}
                        </a>
                    {% endfor %}
                </div>
            </div>
            {% if global.location.site %}
                <div class="item {% if request.url.startsWith(global.urls.resolveSite(global.location.site)) %}active{% endif %}"><i class="cubes icon"></i>Entities
                    <div class="menu">
                        <a href="{{ global.urls.resolveSite(global.location.site) }}" class="item {% if request.url == global.urls.resolveSite(global.location.site) %}active{% endif %}">All</a>
                        {% for entityCategory in global.entityCategories.getItems() %}
                            {% if entityCategory.isGlobal == false %}
                                <a href="{{ global.urls.resolveEntityCategory(global.location.site, entityCategory) }}" class="item {% if entityCategory and entityCategory.isEqualTo(global.location.entityCategory) %}active{% endif %}">
                                    {{ entityCategory.pluralName }}
                                </a>
                            {% endif %}
                        {% endfor %}
                    </div>
                </div>
                {% if global.navigation.site %}
                    {% for item in global.navigation.site %}
                        <a href="{{ item.link }}" class="item {% if request.url.startsWith(item.link) %}active{% endif %}"><i class="{{ item.icon }} icon"></i>{{ item.text }}</a>
                    {% endfor %}
                {% endif %}
            {% endif %}
        </div>
    </div>

{% endmacro %}
