{% load horizon i18n %}
{% load url from future %}

<dl class="nav_accordion">
{% for dashboard, panel_info in components %}
  {% if user|has_permissions:dashboard %}
    <dt {% if current.slug == dashboard.slug %}class="active"{% endif %}>
      {{ dashboard.name }}
      <span class="fa pull-right"></span>
    </dt>
    {% if current.slug == dashboard.slug %}
    <dd>
    {% else %}
    <dd style="display:none;">
    {% endif %}
    {% for heading, panels in panel_info.iteritems %}
      {% with panels|has_permissions_on_list:user as filtered_panels %}
      {% if filtered_panels %}
        {% if heading %}
        <div>
          <h4>
            {{ heading }}
            <span class="fa pull-right"></span>
          </h4>
        {% endif %}
        <ul{% if heading and heading != current_panel_group %} class="hidden"{% endif %}>
        {% for panel in filtered_panels %}
          <li><a href="{{ panel.get_absolute_url }}" {% if current.slug == dashboard.slug and current_panel == panel.slug %}class="active"{% endif %} tabindex="{{ forloop.counter }}" >{{ panel.name }}</a></li>
        {% endfor %}
        </ul>
        {% if heading %}
          </div>
        {% endif %}
      {% endif %}
      {% endwith %}
    {% endfor %}
    </dd>
  {% endif %}
{% endfor %}
</dl>
