import React, { PureComponent } from 'react';

import Field from './Field';

class CreateRuleForm extends PureComponent {
  constructor(props) {
    super();
    this.state = {
      id: '',
      title: '',
      body: '',
      idIfTrue: '',
      idIfFalse: ''
    };
    this.onCreateRule = this.onCreateRule.bind(this);
    this.onFieldChange = this.onFieldChange.bind(this);
  }

  onCreateRule(event) {
    event.preventDefault();
    this.form.reset();
    this.props.onCreateRule(this.state);
  }

  onFieldChange(event) {
    this.setState({ [event.target.name]: event.target.value });
  }

  render() {
    return (
      <div>
        <h2>1. Create flow</h2>
        <form action="#" onSubmit={this.onCreateRule} ref={(form) => { this.form = form; }}>
          <fieldset>
            <legend>New Rule</legend>

            <Field name="title" placeholder="A nice title" onChange={this.onFieldChange} />
            <Field name="id" placeholder="ex. 1" onChange={this.onFieldChange} />
            <Field name="body" placeholder="ex. 1">
              <textarea name="body" placeholder="// a nice an clean javascript function here" defaultValue="" onChange={this.onFieldChange} />
            </Field>
            <Field name="idIfTrue" label="Id if it passes" placeholder="ex. 2" onChange={this.onFieldChange} />
            <Field name="idIfFalse" label="Id if it fails" placeholder="ex. 3" onChange={this.onFieldChange} />

            <input type="submit" name="create" value="Add new rule" />
          </fieldset>
        </form>
      </div>
    );
  }
}

export default CreateRuleForm;

@@ -1021,36 +1021,16 @@
 e=%22body%22
- placeholder=%22ex. 1%22
 %3E%0A      
@@ -1046,28 +1046,60 @@
 textarea
- name=%22body%22
+%0A                name=%22body%22%0A               
  placeho
@@ -1152,24 +1152,56 @@
 ere%22
- defaultValue=%22%22
+%0A                defaultValue=%22%22%0A               
  onC
@@ -1218,32 +1218,46 @@
 s.onFieldChange%7D
+%0A             
  /%3E%0A            

fix code style on CreateRuleForm