"use strict";
var task_utils_1 = require("./task.utils");
var debug = require('debug')('cb:command.run');
var Rx = require('rx');
var Immutable = require('immutable');
var logger_1 = require('./logger');
var task_resolve_1 = require("./task.resolve");
var command_run_1 = require("./command.run");
var task_list_1 = require("./reporters/task.list");
var reporter_resolve_1 = require("./reporter.resolve");
function prompt(cli, input, config, reporter) {
    var inquirer = require('inquirer');
    var resolved = task_resolve_1.resolveTasks(Object.keys(input.tasks), {
        shared: new Rx.BehaviorSubject(Immutable.Map({})),
        cli: cli,
        input: input,
        config: config,
        reporter: reporter,
        type: command_run_1.TriggerTypes.command
    });
    if (resolved.invalid.length) {
        reporter({ type: reporter_resolve_1.ReportTypes.TaskTree, data: { tasks: resolved.all, config: config, title: 'Available tasks:' } });
        return Rx.Observable.empty();
    }
    else {
        var taskSelect = {
            type: "checkbox",
            message: "Select Tasks to run with <space>",
            name: "tasks",
            choices: getTaskList(resolved.valid),
            validate: function (answer) {
                if (answer.length < 1) {
                    return "You must choose at least one task";
                }
                return true;
            }
        };
        return Rx.Observable.fromPromise(inquirer.prompt(taskSelect));
    }
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = prompt;
function getTaskList(tasks) {
    var topLevelTasks = tasks.filter(function (x) { return !task_utils_1.isInternal(x.baseTaskName); });
    var col = task_list_1.twoCol(topLevelTasks);
    return col.map(function (tuple, i) {
        return {
            name: logger_1.compile(tuple[0] + " " + tuple[1]),
            value: topLevelTasks[i].baseTaskName
        };
    });
}
exports.getTaskList = getTaskList;
//# sourceMappingURL=command.run.interactive.js.map