import React, { Component } from 'react'; // eslint-disable-line no-unused-vars
import styles from './Menu.less'; // eslint-disable-line no-unused-vars
import withStyles from '../../decorators/withStyles'; // eslint-disable-line no-unused-vars
import Link from '../../utils/Link';

// Store
import MenuActions from '../../actions/MenuActions';
import MenuStore from '../../stores/MenuStore';

@withStyles(styles)
class Menu extends Component {

  constructor(props) {
    super(props);

    this.state = {
      active: MenuStore.getState()
    };

    // Binds
    this.handleClick = this.handleClick.bind(this);
    this.onChange = this.onChange.bind(this);

    // Listen for change
    MenuStore.onChange(this.onChange);
  }

  componentWillUnmount() {
    MenuStore.off(this.onChange);
  }

  render() {
    if(this.state.active){
      var menu = <img src={require('./close.png')} />;
    } else {
      menu = <img src={require('./burger.png')} />;
    }

    return (
      <div className={this.state.active ? 'Menu--active animated fadeIn' : 'Menu animated fadeIn'}>
        <div className="Menu-openLink" onClick={this.handleClick}>
          {menu}
          <span className="Menu-textLink">{this.state.active ? 'Fermer' : 'Menu'}</span>
        </div>
        <div className="Menu-container">
          <div className="Menu-content">
            <ul>
              <li>
                <a href='a-propos' onClick={Link.handleClick} className={this.props.path === '/a-propos' ? 'disabled' : ''}>
                  <span data-letters="A propos">A propos</span>
                </a>
              </li>
              <li>
                <a href='application' onClick={Link.handleClick} className={this.props.path === '/application' ? 'disabled' : ''}>
                  <span data-letters="L'application">L'application</span>
                </a>
              </li>
              <li>
                <a href='communaute' onClick={Link.handleClick} className={this.props.path === '/communaute' ? 'disabled' : ''}>
                  <span data-letters="Communauté">Communauté</span>
                </a>
              </li>
              <li>
                <a href='contact' onClick={Link.handleClick} className={this.props.path === '/contact' ? 'disabled' : ''}>
                  <span data-letters="Contact">Contact</span>
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    );
  }

  handleClick() {
    MenuActions.toggle(!this.state.active);
  }

  onChange() {
    this.setState({ active: MenuStore.getState() });
  }

}

export default Menu;
