const InputValidate = require('webpack-addons').InputValidate;
const validate = require('./validate');

module.exports = (self, answer) => {
	let entryIdentifiers;
	let result;
	if(answer['entryType'] === true) {
		result = self.prompt([
			InputValidate(
				'multipleEntries',
				'Type the name you want for your modules (entry files), separated by comma',
				validate
			)
		]).then( (multipleEntriesAnswer) => {
			let webpackEntryPoint = {};
			entryIdentifiers = multipleEntriesAnswer['multipleEntries'].split(',');
			function forEachPromise(obj, fn) {
				return obj.reduce(function (promise, prop) {
					const trimmedProp = prop.trim();
					return promise.then(function (n) {
						if(n) {
							Object.keys(n).forEach( (val) => {
								if(
									n[val].charAt(0) !== '('
									&& n[val].charAt(0) !== '['
									&& n[val].indexOf('function') < 0
									&& n[val].indexOf('path') < 0
									&& n[val].indexOf('process') < 0
								) {
									n[val] = `'${n[val]}.js'`;
								}
								webpackEntryPoint[val] = n[val];
							});
						} else {
							n = {};
						}
						return fn(trimmedProp);
					});
				}, Promise.resolve());
			}
			return forEachPromise(entryIdentifiers, (entryProp) => self.prompt([
				InputValidate(
					`${entryProp}`,
					`What is the location of '${entryProp}'?`,
					validate
				)
			])).then(propAns => {
				Object.keys(propAns).forEach( (val) => {
					if(
						propAns[val].charAt(0) !== '('
						&& propAns[val].charAt(0) !== '['
						&& propAns[val].indexOf('function') < 0
						&& propAns[val].indexOf('path') < 0
						&& propAns[val].indexOf('process') < 0
					) {
						propAns[val] = `'${propAns[val]}.js'`;
					}
					webpackEntryPoint[val] = propAns[val];
				});
				return webpackEntryPoint;
			});
		});
	}
	else {
		result = self.prompt([
			InputValidate(
				'singularEntry',
				'Which module will be the first to enter the application?',
				validate
			)
		]).then( (singularAnswer) => `'${singularAnswer['singularEntry']}'`);
	}
	return result;
};

const InputValidate = require('webpack-addons').InputValidate;
const validate = require('./validate');

module.exports = (self, answer) => {
	let entryIdentifiers;
	let result;
	if(answer['entryType'] === true) {
		result = self.prompt([
			InputValidate(
				'multipleEntries',
				'Type the name you want for your modules (entry files), separated by comma [example: \'app\']',
				validate
			)
		]).then( (multipleEntriesAnswer) => {
			let webpackEntryPoint = {};
			entryIdentifiers = multipleEntriesAnswer['multipleEntries'].split(',');
			function forEachPromise(obj, fn) {
				return obj.reduce(function (promise, prop) {
					const trimmedProp = prop.trim();
					return promise.then(function (n) {
						if(n) {
							Object.keys(n).forEach( (val) => {
								if(
									n[val].charAt(0) !== '('
									&& n[val].charAt(0) !== '['
									&& n[val].indexOf('function') < 0
									&& n[val].indexOf('path') < 0
									&& n[val].indexOf('process') < 0
								) {
									n[val] = `'${n[val]}.js'`;
								}
								webpackEntryPoint[val] = n[val];
							});
						} else {
							n = {};
						}
						return fn(trimmedProp);
					});
				}, Promise.resolve());
			}
			return forEachPromise(entryIdentifiers, (entryProp) => self.prompt([
				InputValidate(
					`${entryProp}`,
					`What is the location of '${entryProp}'? [example: '../dist/app.js']`,
					validate
				)
			])).then(propAns => {
				Object.keys(propAns).forEach( (val) => {
					if(
						propAns[val].charAt(0) !== '('
						&& propAns[val].charAt(0) !== '['
						&& propAns[val].indexOf('function') < 0
						&& propAns[val].indexOf('path') < 0
						&& propAns[val].indexOf('process') < 0
					) {
						propAns[val] = `'${propAns[val]}.js'`;
					}
					webpackEntryPoint[val] = propAns[val];
				});
				return webpackEntryPoint;
			});
		});
	}
	else {
		result = self.prompt([
			InputValidate(
				'singularEntry',
				'Which module will be the first to enter the application? [example: \'./index\']',
				validate
			)
		]).then( (singularAnswer) => `'${singularAnswer['singularEntry']}'`);
	}
	return result;
};

add examples for single and multiple entries prompt (#162)