/*
 *
 * Menu
 *
 */

import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { FormattedMessage } from 'react-intl';
import { createStructuredSelector } from 'reselect';
import messages from './messages';
import { selectMenu } from './actions';
import { editBabyName } from 'containers/EditBabyName/actions';

export class Menu extends React.PureComponent { // eslint-disable-line react/prefer-stateless-function
  render() {
    const { menu, personChooser, onButtonClick, onBackButtonClick } = this.props;

    if (personChooser) {
      if (!menu) {
        return (
          <div>
            <h1>Menu</h1>

            <form>
              <input type="button" value={messages.addBabyName.defaultMessage} onClick={() => {
                onButtonClick("addBabyName")
              }}></input>

              <input type="button" value={messages.rateBabyName.defaultMessage} onClick={() => {
                onButtonClick("rateBabyName")
              }}></input>          

              <input type="button" value={messages.listBabyNames.defaultMessage} onClick={() => {
                onButtonClick("listBabyNames")
              }}></input>

            </form>
          </div>
        );
      }

      return (
        <form>
          <input type="button" value={messages.back.defaultMessage} onClick={() => {
            onBackButtonClick();
            onButtonClick("");
          }}></input>
        </form>
      );  
    }
    
    return null;
  }
}

Menu.propTypes = {
};

const mapStateToProps = (state) => {
  return {
    menu: state.toObject().menu,
    personChooser: state.toObject().personChooser
  };
}

function mapDispatchToProps(dispatch) {
  return {
    onButtonClick: (link) => {
      dispatch(selectMenu(link));
    },

    onBackButtonClick: () => {
      dispatch(editBabyName(""));
    }
  };
}

export default connect(mapStateToProps, mapDispatchToProps)(Menu);

@@ -517,16 +517,35 @@
 tonClick
+, onListButtonClick
  %7D = thi
@@ -553,16 +553,16 @@
 .props;%0A
-
 %0A    if 
@@ -1254,16 +1254,460 @@
      %7D%0A%0A
+      if (menu === %22rateBabyName%22) %7B%0A        return (%0A          %3Cform%3E%0A            %3Cinput type=%22button%22 value=%7Bmessages.back.defaultMessage%7D onClick=%7B() =%3E %7B%0A              onBackButtonClick();%0A              onButtonClick(%22%22);%0A            %7D%7D%3E%3C/input%3E%0A%0A            %3Cinput type=%22button%22 value=%7Bmessages.listBabyNames.defaultMessage%7D onClick=%7B() =%3E %7B%0A              onListButtonClick();%0A            %7D%7D%3E%3C/input%3E%0A          %3C/form%3E%0A        );%0A      %7D%0A%0A
       re
@@ -1923,18 +1923,16 @@
       );
-  
 %0A    %7D%0A 
@@ -2272,24 +2272,24 @@
 ck: () =%3E %7B%0A
-
       dispat
@@ -2306,24 +2306,142 @@
 yName(%22%22));%0A
+    %7D,%0A%0A    onListButtonClick: () =%3E %7B%0A      dispatch(editBabyName(%22%22));%0A      dispatch(selectMenu(%22listBabyNames%22));%0A
     %7D%0A  %7D;%0A%7D

Add list button to rate baby names page