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

<div>
  <dl class="nav_accordion">
  {% for dashboard, panel_info in components %}
    {% if user|has_permissions:dashboard %}
      {% if dashboard.supports_tenants and request.user.authorized_tenants or not dashboard.supports_tenants %}
        <dt {% if current.slug == dashboard.slug %}class="active"{% endif %}>
          <div>{{ dashboard.name }}</div>
        </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><div>{{ heading }}</div></h4>
            {% endif %}
            <ul>
            {% 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 %} >{{ panel.name }}</a></li>
            {% endfor %}
            </ul>
            {% if heading %}
              </div>
            {% endif %}
          {% endif %}
          {% endwith %}
        {% endfor %}
        </dd>
      {% endif %}
    {% endif %}
  {% endfor %}
  </dl>
</div>

