'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports.default = function (schema) {
  return function () {
    return new Promise(function (resolve, reject) {
      (_loader || _load_loader()).default.stop();
      (_prompt || _load_prompt()).default.start();
      (_prompt || _load_prompt()).default.message = DEFAULT_PROMPT_MSG;

      (_prompt || _load_prompt()).default.get(schema, function (err, res) {
        if (err) {
          if (err.message === CANCEL_ERROR_MSG) {
            reject(new (_exceptions || _load_exceptions()).PromptCanceled());
          }
          return reject(err);
        }
        (_loader || _load_loader()).default.start();
        return resolve(res);
      });
    });
  };
};

var _prompt;

function _load_prompt() {
  return _prompt = _interopRequireDefault(require('prompt'));
}

var _loader;

function _load_loader() {
  return _loader = _interopRequireDefault(require('../cli/loader'));
}

var _exceptions;

function _load_exceptions() {
  return _exceptions = require('./exceptions');
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var DEFAULT_PROMPT_MSG = '';

var CANCEL_ERROR_MSG = 'canceled';