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

  This file is part of Invenio.
  Copyright (C) 2015-2021 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.
#}


{%- if config.ACCOUNTS %}
    {%- if not current_user.is_authenticated %}
        <form>
            <a href="{{ url_for_security('login', next=request.path) }}"
               class="ui button">
                <i class="sign-in icon"></i>
                {{ _('Log in') }}</a>
            {% if security.registerable %}
                <a href="{{ url_for_security('register') }}" class="ui button signup">
                    <i class="edit outline icon"></i>
                    {{ _('Sign up') }}
                </a>
            {% endif %}
        </form>
    {%- else %}

        {# Quick-create ("plus") menu #}
        {%- set plus_menu_items = current_menu.submenu('plus').children %}
        {%- if plus_menu_items %}
          <div class="rdm-plus-menu rdm-plus-menu-responsive ui dropdown floating pr-15 computer only">
              <i class="fitted plus icon inverted"></i>
              <i class="fitted dropdown icon inverted"></i>
              <div class="menu">
                  {%- for item in plus_menu_items if item.visible %}
                      <a class="item"
                          style="color:black;"
                          href="{{ item.url }}">{{ item.text|safe }}
                      </a>
                  {%- endfor %}
              </div>
          </div>

          <div class="sub-menu mobile only tablet only">
            <h2 class="ui small header">{{ _("Actions") }}</h2>

            {%- for item in plus_menu_items if item.visible %}
              <a class="item" href="{{ item.url }}">
                <i class="plus icon"></i>
                {{ item.text|safe }}
              </a>
            {%- endfor %}
          </div>
        {% endif %}

        {%- if config.USERPROFILES %}
          <div id="user-profile-dropdown" class="ui floating dropdown computer only">
            <button id="user-profile-dropdown-btn"
                    class="ui right labeled right floated icon button text"
                    aria-controls="user-profile-menu"
                    aria-expanded="false"
                    aria-haspopup="menu"
                    aria-label="{{ _('My account') }}"
            >
              <span>
                <i class="user icon"></i>
                {{ current_user.email|truncate(31,true) }}
              </span>
              <i class="dropdown icon"></i>
            </button>

            <div id="user-profile-menu"
                 class="ui menu"
                 role="menu"
                 aria-labelledby="user-profile-dropdown-btn"
            >
              {%- for item in current_menu.submenu('settings').children if item.visible %}
                <a role="menuitem" class="item" href="{{ item.url }}" tabindex="-1">
                  {{ item.text|safe }}
                </a>
              {%- endfor %}

              <div class="divider"></div>
              <a role="menuitem" class="item" href="{{ url_for_security('logout') }}" tabindex="-1">
                <i class="sign-out icon"></i>
                {{ _('Log out') }}
              </a>
            </div>
          </div>

          <div class="sub-menu mobile only tablet only">
            <h2 class="ui small header">{{ _("My account") }}</h2>

            {%- for item in current_menu.submenu('settings').children if item.visible %}
              <a class="item" href="{{ item.url }}">
                {{ item.text|safe }}
              </a>
            {%- endfor %}

            <div class="ui divider"></div>

            <a class="item" style="color:black;" href="{{ url_for_security('logout') }}">
                <i class="sign-out icon"></i>
                {{ _('Log out') }}
            </a>
          </div>

        {%- else %}
          <a role="button" href="{{ url_for_security('logout') }}" class="ui button">
            <i class="sign-out icon"></i>
            {{ _('Log out') }}
          </a>
        {%- endif %}
    {%- endif %}
{%- endif %}
