/*
Copyright 2016 OpenMarket Ltd

Licensed 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.
*/

'use strict';

import React from 'react';
import dis from '../../../dispatcher';
import AccessibleButton from '../elements/AccessibleButton';

// cancel button which is shared between room header and simple room header
export function CancelButton(props) {
    const {onClick} = props;

    return (
        <AccessibleButton className='mx_RoomHeader_cancelButton' onClick={onClick}>
            <img src="img/cancel.svg" className='mx_filterFlipColor'
                width="18" height="18" alt="Cancel"/>
        </AccessibleButton>
    );
}

/*
 * A stripped-down room header used for things like the user settings
 * and room directory.
 */
export default React.createClass({
    displayName: 'SimpleRoomHeader',

    propTypes: {
        title: React.PropTypes.string,
        onCancelClick: React.PropTypes.func,

        // is the RightPanel collapsed?
        collapsedRhs: React.PropTypes.bool,
    },

    onShowRhsClick: function(ev) {
        dis.dispatch({ action: 'show_right_panel' });
    },

    render: function() {
        let cancelButton;
        if (this.props.onCancelClick) {
            cancelButton = <CancelButton onClick={this.props.onCancelClick} />;
        }

        let showRhsButton;
        /* // don't bother cluttering things up with this for now.
        const TintableSvg = sdk.getComponent("elements.TintableSvg");

        if (this.props.collapsedRhs) {
            showRhsButton =
                <div className="mx_RoomHeader_button" style={{ float: 'right' }} onClick={this.onShowRhsClick} title=">">
                    <TintableSvg src="img/minimise.svg" width="10" height="16"/>
                </div>
        }
        */

        return (
            <div className="mx_RoomHeader" >
                <div className="mx_RoomHeader_wrapper">
                    <div className="mx_RoomHeader_simpleHeader">
                        { this.props.title }
                        { showRhsButton }
                        { cancelButton }
                    </div>
                </div>
            </div>
        );
    },
});

@@ -696,16 +696,50 @@
 Button';
+%0Aimport sdk from '../../../index';
 %0A%0A// can
@@ -1424,36 +1424,41 @@
  // 
-is the RightPanel collapsed?
+%60src%60 to a TintableSvg. Optional.
 %0A   
@@ -1462,28 +1462,20 @@
         
+i
 co
-llapsedRhs
+n
 : React.
@@ -1488,12 +1488,14 @@
 pes.
-bool
+string
 ,%0A  
@@ -1640,32 +1640,50 @@
 t cancelButton;%0A
+        let icon;%0A
         if (this
@@ -1795,16 +1795,287 @@
        %7D
+%0A        if (this.props.icon) %7B%0A            const TintableSvg = sdk.getComponent('elements.TintableSvg');%0A            icon = %3CTintableSvg%0A                className=%22mx_RoomHeader_icon%22 src=%7Bthis.props.icon%7D%0A                width=%2225%22 height=%2225%22%0A            /%3E;%0A        %7D
 %0A%0A      
@@ -2662,24 +2662,24 @@
 r_wrapper%22%3E%0A
-
             
@@ -2727,24 +2727,57 @@
 pleHeader%22%3E%0A
+                        %7B icon %7D%0A
             

Add optional tintable SVG icon for SimpleRoomHeader