
{% macro sidebar_menu(menu, id=None, is_submenu=0, nav_classes="") -%}
{% if not is_submenu %}
  <ul {%if id%}id="{{id}}"{%endif%} data-widget="treeview" role="menu" data-accordion="false" class="nav nav-pills nav-sidebar flex-column {{nav_classes}}">
{% endif %}
{% for item in menu %}
  {% if item.type == item.TYPE_HEADER %}
    <li class="nav-header">{{ item.title }}</li>
  {% elif item.type == item.TYPE_FORM %}
    <li class="nav-item">
      <div class="nav-header form-inline" title="{{item.help}}">
        <form action="{{item.url}}" method="post">
        <div class="input-group">
          {% if csrf_token %}
          <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
          {% endif %}
          <input class="form-control form-control-sidebar" name="{{item.form}}" type="text" autocomplete="off" placeholder="{{item.title}}" aria-label="{{item.title}}">
          <div class="input-group-append">
            <button class="btn btn-sidebar">
              {%if item.icon%}<i class="{{item.icon}}"></i>{%endif%}
            </button>
            {% if item.badge %}
            <span class="right badge badge-{{ item.badge.1 }}">{{ item.badge.0 }}</span>
          {% endif %}
          </div>
        </div>
        </form>
      </div>  
    </li>
  {% elif item.type == item.TYPE_LINK %}
    <li class="nav-item{% if item.has_children() %} has-treeview {% if item.is_active() %} menu-open{% endif %}{% endif %}">
      <a class="nav-link{% if item.is_active() %} active{% endif %}" href="{{ item.url }}" title="{{ item.help }}">
        <i class="nav-icon {% if item.icon %}{{ item.icon }}{% else %}far fa-circle{% endif %}"></i>
        <p>
          {{ item.title }}
          {% if item.has_children() %}
            <i class="right fas fa-angle-left"></i>
          {% endif %}
          {% if item.badge %}
            <span class="right badge badge-{{ item.badge.1 }}">{{ item.badge.0 }}</span>
          {% endif %}
        </p>
      </a>
      {% if item.has_children() %}
        <ul class="nav nav-treeview">
          {{ sidebar_menu(menu=item.children, is_submenu=1) }}
        </ul>
      {% endif %}
    </li>
  {% endif %}
{% endfor %}
{% if not is_submenu %}</ul>{% endif %}
{%- endmacro %}