{% extends 'allianceauth/base.html' %}

{% load i18n %}
{% load static %}
{% load custom_filters %}

{% block page_title %}{% translate "Wiki" %}{% endblock %}

{% block content %}
<div class="allianceauth-afatstat-plugin">
    <br />
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                {% if False %}
                <a class="navbar-brand">
                    <i class="fas fa-book"></i>
                    Wiki
                </a>
                {% endif %}
                
            </div>
    
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                {% for menu_item in menu_items %}
                    {# Check if menu is the parent #}
                    {% if not menu_item.parent %}
                        {# Check if the menu has any children #}
                        {% if menu_item|has_menu_children %}
                            {# Check if the user is in at least one required group #}
                            {% if menu_item|user_access_any_submenus:user_groups %}
                                {% with submenu_paths=menu_item|get_submenu_paths %}
                                <li class="dropdown {% if current_path|any_paths_current:submenu_paths %}active{% endif %}">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                        <i class="{{ menu_item.icon }}" style="display: inline-block;"></i>
                                        {{ menu_item.title }} 
                                        <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                    {% with menu_children=menu_item|get_menu_children %}
                                        {% for sub_menu_item in menu_children %}
                                            {% if not sub_menu_item.groups or user_groups|is_user_in_groups:sub_menu_item.groups %}
                                            <li>
                                                <a href="{% url 'simplewiki:dynamic_menu' menu_name=sub_menu_item.path %}">
                                                    <i class="{{ sub_menu_item.icon }}" style="display: inline-block;"></i>
                                                    {{ sub_menu_item.title }}
                                                </a>
                                            </li>
                                            {% endif %}
                                        {% endfor %}
                                    {% endwith %}
                                    </ul>
                                </li>
                                {% endwith %}
                            {% endif %}
                        {# Check if the menu doesn't have any children -> must be a parent #}
                        {% else %}
                            {% url 'simplewiki:dynamic_menu' menu_name=menu_item.path as expected_path %}
                            {% if not menu_item.groups or user_groups|is_user_in_groups:menu_item.groups %}
                            <li class="navbar-text {% if current_path == expected_path %}active{% endif %}">
                                <a href="{% url 'simplewiki:dynamic_menu' menu_name=menu_item.path %}" style="display: inline-block;">
                                    <i class="{{ menu_item.icon }}" style="display: inline-block;"></i>
                                    {{ menu_item.title }}
                                </a>
                            </li>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                {% endfor %} 
                </ul>

                <ul class="nav navbar-nav pull-right">
                    <li class="navbar-text {% if current_path == '/wiki/search/' %}active{% endif %}">
                        <a href="{% url 'simplewiki:search' %}">
                            <i class="fas fa-search"></i>
                            Search
                        </a>
                    </li>
                    {% if is_editor is True %}
                        <li class="dropdown {% if current_path == '/wiki/editor/menus/' or current_path == '/wiki/editor/sections/' %}active{% endif %}">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                <i class="fas fa-user-cog"></i>
                                Editor 
                                <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="{% url 'simplewiki:editor_menus' %}">
                                        <i class="fas fa-folder-open"></i>
                                        Menus
                                    </a>
                                </li>
                                <li>
                                    <a href="{% url 'simplewiki:editor_sections' %}">
                                        <i class="fas fa-pen"></i>
                                        Sections
                                    </a>
                                </li>
                                {% if False %}
                                <li>
                                    <a href="{% url 'simplewiki:editor_sort' %}">
                                        <i class="fas fa-pen"></i>
                                        Sort
                                    </a>
                                </li>
                                {% endif %}
                            </ul>
                        </li>
                    {% endif %}
                  </ul>
            </div>
        </div>
    </nav>

    {% block details %}{% endblock %}
</div>
{% endblock %}

{% block extra_css %}
<link rel="stylesheet" type="text/css" href="{% static 'simplewiki/custom.css' %}" />
{% endblock %}

