'use strict';

var _ = require('lodash');

var projectQuestions = [
    {
        type: 'input',
        name: 'projectName',
        message: 'What do you want to name this project?',
        default: 'omaha-project'
    },
    {
        type: 'input',
        name: 'sourceDirectory',
        message: 'Where do you want to put the source code?',
        default: './'
    },
    {
        type: 'confirm',
        name: 'benchmark',
        message: 'Add benchmarking support using Benchmark.js?',
        default: true
    },
    {
        type: 'confirm',
        name: 'coveralls',
        message: 'Integrate with Coveralls.io?',
        default: true
    },
    {
        type: 'confirm',
        name: 'jsinspect',
        message: 'Detect copy-pasted and structurally similar code with JS Inspect?',
        default: true
    }
];
var webappQuestions = [
    {
        type: 'list',
        name: 'scriptBundler',
        message: 'Which technology for bundling scripts before deployment?',
        choices: ['requirejs', 'browserify']
    },
    {
        type: 'list',
        name: 'cssPreprocessor',
        message: 'Which CSS pre-processor?',
        choices: ['less', 'Sass', 'none']
    },
    {
        type: 'list',
        name: 'templateTechnology',
        message: 'Which technology for templates?',
        choices: ['handlebars', 'underscore']
    },
    {
        type: 'confirm',
        name: 'aria',
        message: 'Enforce ARIA and Section 508 standards?',
        default: true
    },
    {
        type: 'confirm',
        name: 'imagemin',
        message: 'Use image compression for deployed application?',
        default: true
    }
];
var getPromptQuestions = _.curry(function(type, isWebapp) {
    var questionLookup = {
        project: projectQuestions,
        webapp: webappQuestions
    };
    return questionLookup[type].map(promptMessageFormat(type, isWebapp));
});
var webappDefaults = webappQuestions
    .map(question => _.pick(question, ['name', 'default', 'choices']))
    .map(i =>_.set({}, i.name, Array.isArray(i.choices) ? _.head(i.choices) : i.default))
    .reduce(_.extend);
var defaults = {
    project: projectQuestions
        .map(question => _.set({}, question.name, question.default))
        .reduce(_.extend),
    webapp: _.extend(webappDefaults, {
        useBrowserify: webappDefaults.scriptBundler === 'browserify',
        useLess: webappDefaults.cssPreprocessor === 'less',
        useSass: webappDefaults.cssPreprocessor !== 'less',
        useHandlebars: webappDefaults.templateTechnology === 'handlebars'
    })
};

function promptMessageFormat(type, isWebapp) {
    function addLeadingZero(step) {return (step < 10) ? ('0' + step) : step;}
    var total = projectQuestions.length;
    total += isWebapp ? webappQuestions.length : 0;
    return function(question, index) {
        var step = index + 1 + ((type === 'webapp') ? projectQuestions.length : 0);
        question.message = require('chalk')[step === total ? 'green' : 'gray']('(' + addLeadingZero(step) + '/' + total + ') ') + question.message;
        return question;
    };
}

exports.project = {
    defaults: defaults.project,
    getQuestions: getPromptQuestions('project')
};
exports.webapp = {
    defaults: defaults.webapp,
    getQuestions: getPromptQuestions('webapp')
};

@@ -2025,16 +2025,19 @@
   .map(i
+tem
  =%3E_.set
@@ -2042,16 +2042,19 @@
 et(%7B%7D, i
+tem
 .name, A
@@ -2067,16 +2067,19 @@
 sArray(i
+tem
 .choices
@@ -2087,15 +2087,13 @@
  ? _
-.head(i
+(item
 .cho
@@ -2101,12 +2101,37 @@
 ces)
+.map(_.toLower).head()
  : i
+tem
 .def
@@ -2524,15 +2524,15 @@
 sor 
-!
+=
 == '
-le
+sa
 ss',

Set useSass based on value being sass, not not less