"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

function _prompt() {
  const data = _interopRequireDefault(require("prompt"));

  _prompt = function () {
    return data;
  };

  return data;
}

function _loader() {
  const data = _interopRequireDefault(require("../cli/loader"));

  _loader = function () {
    return data;
  };

  return data;
}

function _exceptions() {
  const data = require("./exceptions");

  _exceptions = function () {
    return data;
  };

  return data;
}

const DEFAULT_PROMPT_MSG = '';
const CANCEL_ERROR_MSG = 'canceled';

function _default(schema) {
  return function () {
    return new Promise((resolve, reject) => {
      _loader().default.stop();

      _prompt().default.start();

      _prompt().default.message = DEFAULT_PROMPT_MSG;

      _prompt().default.get(schema, (err, res) => {
        if (err) {
          if (err.message === CANCEL_ERROR_MSG) {
            reject(new (_exceptions().PromptCanceled)());
          }

          return reject(err);
        }

        _loader().default.start();

        return resolve(res);
      });
    });
  };
}