import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { push } from '../redux/actions';

// TODO: Link should have an option to scroll to the top, and should by default scroll to a #hash
class Link extends React.Component {
  constructor() {
    super();
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(event) {
    if (this.props.onClick) {
      this.props.onClick(event);
    }

    if (event.button !== 0
      || event.metaKey
      || event.altKey
      || event.ctrlKey
      || event.shiftKey
      || event.defaultPrevented === true) {
      return;
    }

    event.preventDefault();

    this.props.dispatch(push(this.props.to));
  }

  render() {
    const { to, children, dispatch, ...rest } = this.props;
    // eslint-disable-next-line jsx-a11y/anchor-has-content
    return (
      <a href={this.props.to} onClick={this.handleClick} {...rest}>
        {this.props.children}
      </a>
    );
  }
}

Link.propTypes = {
  to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
  onClick: PropTypes.func,
  children: PropTypes.node,
  dispatch: PropTypes.func,
};

const LinkContainer = connect()(Link);

export { LinkContainer };

@@ -644,17 +644,16 @@
 ault();%0A
-%0A
     this
@@ -772,68 +772,8 @@
 ps;%0A
-    // eslint-disable-next-line jsx-a11y/anchor-has-content%0A
     
@@ -796,27 +796,16 @@
 a href=%7B
-this.props.
 to%7D onCl
@@ -840,30 +840,11 @@
 est%7D
-%3E%0A        %7Bthis.props.
+ %3E%7B
 chil
@@ -848,23 +848,16 @@
 hildren%7D
-%0A      
 %3C/a%3E%0A   

Update Link component