div id="user_widget"
  .PopNavigation.PopNavigation--docs
    a.PopNavigation-trigger.u-toggler class=('is-current' if active_menu?(:topmenu, :help)) href="#documentation-menu" title="Documentation"
      => icon('info-circle')
      | Documentation
    ul#documentation-menu.PopNavigation-list.u-toggleable
      li.PopNavigation-listItem
        = render 'shared/docs_widget'
      li.PopNavigation-listItem
        = fixed_width_icon_link_to 'Support Website', 'external-link', '//support.3scale.net/', class: 'PopNavigation-link', target: '_blank'
      li.PopNavigation-listItem
        = fixed_width_icon_link_to '3scale API Docs', 'puzzle-piece', provider_admin_api_docs_path, class: 'PopNavigation-link'
      li.PopNavigation-listItem
        = fixed_width_icon_link_to 'Liquid Reference', 'code', provider_admin_liquid_docs_path, class: 'PopNavigation-link'

  .PopNavigation.PopNavigation--account
    a.PopNavigation-trigger.u-toggler class=('is-current' if active_menu?(:topmenu, :account)) href="#settings-menu"  title="Account and Personal Settings"
      => icon('cog')
      => icon('bolt') if impersonating?

    ul#settings-menu.PopNavigation-list.u-toggleable
      - if can?(:manage, current_user)
        li.PopNavigation-listItem
          = fixed_width_icon_link_to 'Personal Settings', 'user', edit_provider_admin_user_personal_details_path, class: 'PopNavigation-link'
      - if can?(:manage, current_account)
        li.PopNavigation-listItem
          = fixed_width_icon_link_to 'Account', 'cogs', provider_admin_account_path, class: 'PopNavigation-link'
      li.PopNavigation-listItem
        p.PopNavigation-info
          - if impersonating?
            => icon('bolt')
            ' Impersonating a virtual admin user from
          - else
            ' Signed in to
          => current_user.account.name
          ' as
          = current_user.display_name
          | .

        = fixed_width_icon_link_to 'Sign Out', 'times', provider_logout_path, class: 'PopNavigation-link', title: 'Logout #{current_user.username}'

  ul id="top-menu-nav"
    li class=('active' if active_menu?(:topmenu, :dashboard) )
      = fixed_width_icon_link_to 'Dashboard', 'home', provider_admin_dashboard_path

  // HACK of the month. See features/support/current_user.rb if you are hungry for reasons
  div class="username" style="display:none;"
    = current_user.username


javascript:
  $(document)
    .on('click', '.u-toggler', function(event) {
      $(this).toggleClass('is-toggled');
      var toggleable = $(this).siblings('.u-toggleable')
      toggleable.toggleClass('is-toggled');
      toggleable.find('input').filter(':visible:first').focus();
      return false;
    })

    .on('click', '#docs-widget', function(event) {
      event.stopPropagation();
    })

    .on('click', 'body', function(event){
      var expanded = $(".PopNavigation .is-toggled");
      if (expanded.length > 0) {
        expanded.removeClass("is-toggled");
        event.stopPropagation();
      }
    });
