const { notEmpty } = require('../utils.js')

module.exports = {
  description: 'generate a table-view',
  prompts: [{
    type: 'input',
    name: 'name',
    message: '请输入组件目录名',
    validate: notEmpty('name')
  }, {
    type: 'input',
    name: 'title',
    message: '请输入表格标题'
  }, {
    type: 'list',
    name: 'treeType',
    message: '请选择侧边树',
    choices: [{
      name: '<HybridTree>',
      value: 'hybridTree'
    },
    {
      name: '<ParkTree>',
      value: 'parkTree'
    },
    {
      name: 'none',
      value: ''
    }],
    validate(value) {
      if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
        return 'View require at least a <script> or <template> tag.'
      }
      return true
    }
  }],
  actions: data => {
    const name = '{{name}}'
    const title = '{{title}}'
    const treeType = '{{treeType}}'
    const actions = [{
      type: 'add',
      path: `src/views/${name}/index.vue`,
      templateFile: 'plop-templates/table-view/index.hbs',
      data: {
        name: name,
        title: title,
        treeType: treeType
      }
    }, {
      type: 'add',
      path: `src/views/${name}/components/table.vue`,
      templateFile: 'plop-templates/table-view/components/table.hbs',
      data: {
        name: name,
        title: title,
        treeType: treeType
      }
    }, {
      type: 'add',
      path: `src/views/${name}/components/conditions.vue`,
      templateFile: 'plop-templates/table-view/components/conditions.hbs',
      data: {
        name: name,
        title: title,
        treeType: treeType
      }
    }, {
      type: 'add',
      path: `src/views/${name}/components/detail.vue`,
      templateFile: 'plop-templates/table-view/components/detail.hbs',
      data: {
        name: name,
        title: title,
        treeType: treeType
      }
    }]

    return actions
  }
}
