content: import _ from 'lodash';
  import React from 'react';
  import PropTypes from 'prop-types';
  import {getForm} from 'elza-core';
  
  /**
   * Submit button
   */
  class Submit extends React.Component {
    static displayName = 'Submit';
    static propTypes = {
      className: PropTypes.string,
      htmlFor: PropTypes.string.isRequired,
      disabled: PropTypes.bool,
    };
  
    static defaultProps = {
      className: '',
      disabled: false,
    };
  
    /**
     * @constructor
     * @param  {Object} props
     */
    constructor(props) {
      super(props);
      this.form = null;
      this.state = {hasErrors: false};
      _.bindAll(this, 'receiveErrors');
    }
  
    receiveErrors(formData) {
      console.log('receive stuf', formData.errors);
      this.setState({hasErrors: formData.errors.any()});
    }
  
    componentDidMount() {
      this.form = getForm(this.props.htmlFor);
      this.form.onChange(this.receiveErrors);
      this.form.onAfter('validation', this.receiveErrors);
      this.form.onAfter('submit', this.receiveErrors);
    }
  
    /**
     * @override
     */
    render() {
      let {className, disabled, htmlFor, type, ...otherProps} = this.props;
      disabled = disabled || this.state.hasErrors;
      console.log('has errors: ', this.state.hasErrors);
      if (disabled) {
        otherProps['disabled'] = true;
        className += ' is-disabled';
      }
      return <button className={className} type="submit" {...otherProps} />;
    }
  }
  
  export default Submit;
  