/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import React from 'react'
import {Link} from "react-router-dom";
import AuthManager from '../../../data/AuthManager.js';

const Header = (props) => {
    return (
        <header className="header header-default">
            <div className="container-fluid">
                <div id="nav-icon1" className="menu-trigger navbar-left " data-toggle="sidebar"
                     data-target="#left-sidebar" data-container=".page-content-wrapper" data-container-divide="true"
                     aria-expanded="false" rel="sub-nav">
                    <span />
                    <span />
                    <span />
                </div>
                <div className="pull-left brand">
                    <Link to="/">
                        <span>APIM Publisher</span>
                    </Link>
                </div>
                <ul className="nav navbar-right">
                    <li className="visible-inline-block">
                        <a className="dropdown" data-toggle="dropdown" aria-expanded="false">
                <span className="icon fw-stack">
                  <i className="fw fw-circle fw-stack-2x"/>
                  <i className="fw fw-user fw-stack-1x fw-inverse"/>
                </span>
                            <span className="hidden-xs add-margin-left-1x" id="logged-in-username">
                                { AuthManager.getUserName()}
                            <span className="caret"/></span>
                        </a>
                        <ul className="dropdown-menu dropdown-menu-right slideInDown" role="menu">
                            <li><a href="#">Profile Settings</a></li>
                            <li>
                                <Link to="/logout">Logout</Link>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </header >
    );
};

export default Header
@@ -702,16 +702,28 @@
 rt %7BLink
+, withRouter
 %7D from %22
@@ -741,16 +741,16 @@
 r-dom%22;%0A
-
 import A
@@ -796,16 +796,36 @@
 ger.js';
+%0Aimport qs from 'qs'
 %0A%0Aconst 
@@ -846,16 +846,84 @@
 s) =%3E %7B%0A
+    let params = qs.stringify(%7Breferrer: props.location.pathname%7D);%0A
     retu
@@ -1299,95 +1299,8 @@
 v%22%3E%0A
-                    %3Cspan /%3E%0A                    %3Cspan /%3E%0A                    %3Cspan /%3E%0A
     
@@ -2066,16 +2066,50 @@
 User
-Name()%7D%0A
+() ? AuthManager.getUser().name : %22%22%7D%0A    
     
@@ -2441,17 +2441,47 @@
  to=
-%22/logout%22
+%7B%7Bpathname: '/logout', search: params%7D%7D
 %3ELog
@@ -2652,16 +2652,351 @@
  );%0A%7D;%0A%0A
+// Using %60withRouter%60 helper from React-Router-Dom to get the current user location to be used with logout action,%0A// We pass the current path in referrer parameter to redirect back the user to where he/she was after login.%0A// DOC: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/withRouter.md%0A
 export d
@@ -3002,14 +3002,26 @@
 default 
+withRouter(
 Header
+)

Add withRouter helper to get current user route for logout action