/**
 * @file
 */

'use strict';

var generators = require('yeoman-generator');

module.exports = generators.Base.extend({

  constructor: function () {
    generators.Base.apply(this, arguments);
  },

  prompting: function () {
    var asyncWait = this.async();

    var questions = [{
      name: 'machineName',
      message: 'Machine name'
    }, {
      name: 'profileName',
      message: 'Profile full name'
    }, {
      name: 'profileDescription',
      message: 'Description',
      default: 'Auto-generated by "yo drupal-profile"'
    }, {
      type: 'list',
      name: 'drupalCore',
      message: 'Drupal core version',
      choices: ['Drupal 6', 'Drupal 7', 'Drupal 8'],
      default: 'Drupal 7'
    }, {
      type: 'confirm',
      name: 'inheritBasicProfile',
      message: 'Inherit from "Basic profile"',
      default: false
    }, {
      name: 'theme',
      message: 'Main theme'
    }, {
      type: 'list',
      name: 'adminTheme',
      message: 'Admin theme',
      choices: ['', 'stanley', 'adminimal_theme', 'seven', 'rubik', 'cube'],
      default: 'adminimal_theme'
    }, {
      type: 'checkbox',
      name: 'modules',
      message: 'Modules',
      choices: [
        'devel', 'views', 'ctools', 'entity', 'admin_menu',
        'token', 'pathauto', 'date', 'features', 'panels'
      ]
    }];

    this.prompt(questions, function ( answers ) {
      this.profileName = answers.profileName;
      this.machineName = answers.machineName;
      this.profileDescription = answers.profileDescription;
      this.drupalCore = answers.drupalCore;
      this.inheritBasicProfile = answers.inheritBasicProfile;
      this.theme = answers.theme;
      this.adminTheme = answers.adminTheme;
      this.modules = answers.modules;

      switch (this.drupalCore) {
        case 'Drupal 6':
          this.origModuleName = 'default';
          break;

        default:
          this.origModuleName = this.inheritBasicProfile ? 'standard' : 'minimal';
          break;
      }
      this.origModuleNameUcfirst = this.origModuleName[0].toUpperCase() + this.origModuleName.slice(1);
      this.machineNameUcfirst = this.machineName[0].toUpperCase() + this.machineName.slice(1);

      asyncWait();
    }.bind(this));
  },

  generateStructure: function () {
    this.mkdir(this.machineName);

    switch (this.drupalCore) {
      case 'Drupal 6':
        this._copyFiles([['default.profile', this.machineName + '.profile']]);
        break;

      case 'Drupal 7':
        this._copyFiles([
          [this.origModuleName + '.profile', this.machineName + '.profile'],
          [this.origModuleName + '.info', this.machineName + '.info'],
          [this.origModuleName + '.install', this.machineName + '.install']
        ]);
        this._copyFolders(['translations']);
        break;

      case 'Drupal 8':
        this._copyFiles([
          [this.origModuleName + '.profile', this.machineName + '.profile'],
          [this.origModuleName + '.info.yml', this.machineName + '.info.yml'],
          [this.origModuleName + '.install', this.machineName + '.install'],
          ['src/Tests/' + this.origModuleNameUcfirst + 'Test.php', 'src/Tests/' + this.machineNameUcfirst + 'Test.php']
        ]);
        this._copyFolders(['config']);

        if (this.origModuleName == 'standard') {
          this._copyFiles([[this.origModuleName + '.links.menu.yml', this.machineName + '.links.menu.yml']]);
        }
        break;
    }
  },

  _copyFiles: function( fileNames ) {
    try {
      var generator = this;
      fileNames.forEach(function (fileName) {
        generator.template(generator.drupalCore + '/' + generator.origModuleName + '/' + fileName[0], generator.machineName + '/' + fileName[1]);
      });
    } catch (e) {
      this.log('Files cannot be copied.', fileNames, e);
    }
  },

  _copyFolders: function (folderNames) {
    try {
      var generator = this;
      folderNames.forEach(function (folderName) {
        generator.directory(generator.drupalCore + '/' + generator.origModuleName + '/' + folderName, generator.machineName + '/' + folderName);
      });
    } catch (e) {
      this.log('Folder cannot be copied.', folderNames, e);
    }
  }

});

@@ -2831,16 +2831,55 @@
 pal 8':%0A
+        this._copyFolders(%5B'config'%5D);%0A
         
@@ -3248,16 +3248,17 @@
 st.php'%5D
+,
 %0A       
@@ -3262,47 +3262,89 @@
     
-%5D);%0A        this._copyFolders(%5B'config'
+  %5B'config/install/system.theme.yml', 'config/install/system.theme.yml'%5D%0A        
 %5D);%0A

Copy theme config