/* Copyright (C) 2017 Canonical Ltd. */
'use strict';

const PropTypes = require('prop-types');
const React = require('react');

const ButtonDropdown = require('../button-dropdown/button-dropdown');
/**
  Provides a user menu to the header - shows Profile, Account and Logout links.
  If user is not logged in the user icon is replaced with a login button.
*/
class UserMenu extends React.Component {

  _toggleDropdown() {
    this.refs.buttonDropdown._toggleDropdown();
  }

  _handleProfileClick() {
    this.props.navigateUserProfile();
    this._toggleDropdown();
  }

  render() {
    const controllerAPI = this.props.controllerAPI;
    const showLogin = controllerAPI && !controllerAPI.userIsAuthenticated;
    return (
      <ButtonDropdown
        classes={['user-menu']}
        ref="buttonDropdown"
        icon={showLogin ? this.props.USSOLoginLink : 'user_16'}
        disableDropdown={showLogin}
        listItems={[{
          action: this.props.navigateUserProfile,
          label: 'Profile'
        }, {
          action: this.props.showHelp,
          label: 'GUI help'
        }, {
          element: this.props.LogoutLink
        }]}
        tooltip={showLogin ? '' : 'user'} />);
  }
};

UserMenu.propTypes = {
  LogoutLink: PropTypes.object,
  USSOLoginLink: PropTypes.object,
  controllerAPI: PropTypes.object,
  navigateUserProfile: PropTypes.func.isRequired,
  showHelp: PropTypes.func.isRequired
};

module.exports = UserMenu;

@@ -354,20 +354,20 @@
 on.%0A*/%0Ac
-lass
+onst
  UserMen
@@ -372,222 +372,21 @@
 enu 
-extends React.Component %7B%0A%0A  _toggleDropdown() %7B%0A    this.refs.buttonDropdown._toggleDropdown();%0A  %7D%0A%0A  _handleProfileClick() %7B%0A    this.props.navigateUserProfile();%0A    this._toggleDropdown();%0A  %7D%0A%0A  render()
+= props =%3E
  %7B%0A
-  
   co
@@ -405,21 +405,16 @@
 erAPI = 
-this.
 props.co
@@ -426,18 +426,16 @@
 lerAPI;%0A
-  
   const 
@@ -499,18 +499,16 @@
 icated;%0A
-  
   return
@@ -510,18 +510,16 @@
 eturn (%0A
-  
     %3CBut
@@ -536,18 +536,16 @@
 n%0A      
- 
- 
 classes=
@@ -566,18 +566,16 @@
 %7D%0A      
-  
 ref=%22but
@@ -587,18 +587,16 @@
 opdown%22%0A
-  
       ic
@@ -611,21 +611,16 @@
 Login ? 
-this.
 props.US
@@ -650,18 +650,16 @@
 %7D%0A      
-  
 disableD
@@ -684,18 +684,16 @@
 %7D%0A      
- 
- 
 listItem
@@ -702,34 +702,32 @@
 %7B%5B%7B%0A        
-  
 action: 
 this.props.n
@@ -710,29 +710,24 @@
     action: 
-this.
 props.naviga
@@ -741,34 +741,32 @@
 rofile,%0A        
- 
- 
 label: 'Profile'
@@ -764,34 +764,32 @@
 'Profile'%0A      
-  
 %7D, %7B%0A          a
@@ -785,26 +785,24 @@
         
- 
- 
 action: 
 this.pro
@@ -793,21 +793,16 @@
 action: 
-this.
 props.sh
@@ -809,18 +809,16 @@
 owHelp,%0A
-  
         
@@ -837,33 +837,29 @@
 help'%0A      
-  
 %7D, %7B%0A
-  
         elem
@@ -867,13 +867,8 @@
 nt: 
-this.
 prop
@@ -890,16 +890,12 @@
     
-  
 %7D%5D%7D%0A
-  
     
@@ -939,12 +939,8 @@
 %3E);%0A
-  %7D%0A
 %7D;%0A%0A

Remove unused user menu methods.