'use strict'

const componentExists = require('../utils/componentExists')

module.exports = {
  description: 'Add an unconnected component',
  prompts: [{
    type: 'list',
    name: 'type',
    message: 'Select the type of component',
    default: 'Stateless Function',
    choices: () => ['Stateless Function', 'ES6 Class (Pure)', 'ES6 Class']
  }, {
    type: 'input',
    name: 'name',
    message: 'What should it be called?',
    default: 'Button',
    validate: (value) => {
      if ((/.+/).test(value)) {
        return componentExists(value) ? 'A component or container with this name already exists' : true
      }

      return 'The name is required'
    }
  }],
  actions: (data) => {
    // Generate index.js and index.test.js
    let componentTemplate

    switch (data.type) {
      case 'ES6 Class': {
        componentTemplate = './component/es6.js.hbs'
        break
      }
      case 'ES6 Class (Pure)': {
        componentTemplate = './component/es6.pure.js.hbs'
        break
      }
      case 'Stateless Function': {
        componentTemplate = './component/stateless.js.hbs'
        break
      }
      default: {
        componentTemplate = './component/es6.js.hbs'
      }
    }

    const actions = [{
      type: 'add',
      path: '../../app/components/{{properCase name}}/index.js',
      templateFile: componentTemplate,
      abortOnFail: true
    }, {
      type: 'add',
      path: '../../app/components/{{properCase name}}/tests/index.test.js',
      templateFile: './component/test.js.hbs',
      abortOnFail: true
    }]

    return actions
  }
}

@@ -311,37 +311,46 @@
 ', '
-ES6 Class (Pure)', 'ES6 Class
+React.PureComponent', 'React.Component
 '%5D%0A 
@@ -678,342 +678,267 @@
 %0A  %7D
-%5D,%0A  actions: (data) =%3E %7B%0A    // Generate index.js and index.test.js%0A    let componentTemplate%0A%0A    switch (data.type) %7B%0A      case 'ES6 Class': %7B%0A        componentTemplate = './component/es6.js.hbs'%0A        break%0A      %7D%0A      case 'ES6 Class (Pure)': %7B%0A        componentTemplate = './component/es6.pure.js.hbs'%0A        break%0A      %7D
+, %7B%0A    type: 'confirm',%0A    name: 'wantLoadable',%0A    default: false,%0A    message: 'Do you want to load the component asynchronously?'%0A  %7D%5D,%0A  actions: (data) =%3E %7B%0A    // Generate index.js and index.test.js%0A    let componentTemplate%0A%0A    switch (data.type) %7B
 %0A   
@@ -1112,11 +1112,13 @@
 ent/
-es6
+class
 .js.
@@ -1490,16 +1490,321 @@
     %7D%5D%0A%0A
+    // If they want Loadable.js to laod the component asynchronously%0A    if (data.wantLoadable) %7B%0A      actions.push(%7B%0A        type: 'add',%0A        path: '../../app/components/%7B%7BproperCase name%7D%7D/Loadable.js',%0A        templateFile: './component/loadable.js.hbs',%0A        abortOnFail: true%0A      %7D)%0A    %7D%0A%0A
     retu

refactor to allow Loadable