{# -*- coding: utf-8 -*-

  This file is part of Invenio.
  Copyright (C) 2015-2018 CERN.

  Invenio is free software; you can redistribute it and/or modify it
  under the terms of the MIT License; see LICENSE file for more details.
#}

{% block headerbox %}
<header class="main-header">
  <a href="{{ url_for('admin.index') }}" class="navbar-brand logo">
    <img src="{{ url_for('static', filename=config.THEME_LOGO_ADMIN) }}" alt="{{ config.ADMIN_APPNAME }}" />
  </a>
  <nav class="navbar navbar-static-top" role="navigation">
  <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
    <span class="sr-only">{{ _("Toggle navigation") }}</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </a>
  <ul class="nav navbar-nav">
  {%- for item in current_menu.submenu('main').children if item.visible recursive %}
    {%- if item.children -%}
        <li class="dropdown">.
          <a href="{{ item.url }}" style="display: inline-block; padding-right: 5px;"> {{ item.text|safe }} </a>
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="display: inline-block; padding-left: 5px;">
            <b class="caret"></b>
          </a>
          <ul class="dropdown-menu pull-right">
            {{ loop(item.children) }}
          </ul>
        </li>
    {%- else -%}
    <li{% if item.active %} class="active"{% endif %}><a href="{{ item.url }}">{{ item.text|safe }}</a></li>
    {%- endif -%}
  {%- endfor -%}
  </ul>
    <div class="navbar-custom-menu">
      <ul class="nav navbar-nav">
        <li class="dropdown user">
          {%- set username = current_userprofile.username|default(current_user.email) if current_userprofile else None %}
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">
            <i class="glyphicon glyphicon-user"></i> {{ username or current_user.email }}
            <b class="caret"></b>
          </a>
          <ul class="dropdown-menu">
            <li>
              <div class="navbar-content">
                <div class="row-fluid user-menu">
                  <div class="col-md-2">
                    <i class="fa fa-user fa-2x"></i>
                  </div>
                  <div class="col-md-10">
                    <strong>
                      {{ username or current_user.email }}
                    </strong>
                    {%- if username and username != current_user.email %}
                    <p class="text-muted small">{{ current_user.email }}</p>
                    {%- endif %}
                  </div>
                </div>
              </div>
            </li>
            {%- for item in current_menu.submenu('settings').children if item.visible %}
            {% if loop.first %}<li class="divider"></li>{% endif -%}
            <li><a href="{{ item.url }}">{{ item.text|safe }}</a></li>
            {%- endfor %}
            <li class="divider"></li>
            <li>
              <a href="{{ url_for(config.ADMIN_LOGOUT_ENDPOINT) }}">
                <i class="glyphicon glyphicon-log-out"></i> {{ _('Logout') }}
              </a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
  </nav>
</header>
{% endblock headerbox %}
