{% comment %}
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
{% endcomment %}

{% capture itemurl %}{{ item.url | absolute_url }}{% endcapture %}
{% capture pageurl %}{{ page.url | absolute_url }}{% endcapture %}

{% if itemurl == pageurl %}
    {% assign current = 'active' %}
{% else %}
    {% assign current = '' %}
{% endif %}

{% capture space %}{{ space | size | times: 0 | plus: 1}}{% endcapture %}
{% capture hashpath %}{{ item.url | remove: '/' | strip_newlines}}{% endcapture %}

<li class="nav-item">
    {% unless item.children != nil %}
        <a class="nav-link {{current}}" href="{{ item.url | absolute_url }}" title="Go to {{ item.title }}">
            {{ item.title }}
        </a>
    {% else %}
        <div class="d-flex justify-content-between nav-link main-link {{current}}">
            <a class="p-2" href="{{ item.url | absolute_url }}" title="Go to {{ item.title }}">
                {{ item.title }}
            </a>
            <a class="p-2 align-self-center" data-toggle="collapse" href="#submenu_{{hashpath}}" role="button" aria-expanded="false" aria-controls="submenu_{{hashpath}}">
                <i class="fas fa-chevron-down"></i>
            </a>
        </div>
        <div class="collapse sub-menu" id="submenu_{{hashpath}}">
            <ul class="flex-column nav">
                {% capture level %}{{level}}|{% endcapture %}
                {% for item in item.children %}
                    {%- include sub-menu.html -%}
                {% endfor %}
                {% capture length %}{{ level | size | minus: 1 }}{% endcapture %}
                {% capture level %}{{ level | slice: 1, length | lstrip | rstrip }}{% endcapture %}
            </ul>
        </div>
    {% endunless %}
</li>

