"use strict";

var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
_Object$defineProperty(exports, "__esModule", {
  value: true
});
exports.stopSpinner = exports.resumeSpinner = exports.pauseSpinner = exports.logWithSpinner = exports.failSpinner = void 0;
var _ora = _interopRequireDefault(require("ora"));
var _chalk = _interopRequireDefault(require("chalk"));
const spinner = (0, _ora.default)();
let lastMsg = null;
const logWithSpinner = (symbol, msg) => {
  if (!msg) {
    msg = symbol;
    symbol = _chalk.default.green('✔');
  }
  if (lastMsg) {
    spinner.stopAndPersist({
      symbol: lastMsg.symbol,
      text: lastMsg.text
    });
  }
  spinner.text = ' ' + msg;
  lastMsg = {
    symbol: symbol + ' ',
    text: msg
  };
  spinner.start();
};
exports.logWithSpinner = logWithSpinner;
const stopSpinner = persist => {
  if (lastMsg && persist !== false) {
    spinner.stopAndPersist({
      symbol: lastMsg.symbol,
      text: lastMsg.text
    });
  } else {
    spinner.stop();
  }
  lastMsg = null;
};
exports.stopSpinner = stopSpinner;
const pauseSpinner = () => {
  spinner.stop();
};
exports.pauseSpinner = pauseSpinner;
const resumeSpinner = () => {
  spinner.start();
};
exports.resumeSpinner = resumeSpinner;
const failSpinner = text => {
  spinner.fail(text);
};
exports.failSpinner = failSpinner;