"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _rcNotification = _interopRequireDefault(require("rc-notification"));

var _uuid = _interopRequireDefault(require("uuid"));

var _SuccessRender = require("./components/SuccessRender");

require("./style/index.css");

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var ntiInstance;

function getInstance() {
  return _getInstance.apply(this, arguments);
}

function _getInstance() {
  _getInstance = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
    return regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", new Promise(function (res) {
              if (ntiInstance && ntiInstance.destroy) {
                ntiInstance.destroy();
              }

              _rcNotification["default"].newInstance({
                // 水平居中
                style: {
                  top: "36px",
                  left: "50%",
                  position: "fixed",
                  'transform': 'translate(-50%, 0)',
                  borderRadius: 12
                },
                maxCount: 1,
                className: "document-mouse-event-ignore",
                getContainer: function getContainer() {
                  return document.body;
                }
              }, function (ins) {
                ntiInstance = ins;
                res(ins);
              });
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _getInstance.apply(this, arguments);
}

var Toast = /*#__PURE__*/function () {
  function Toast() {
    _classCallCheck(this, Toast);
  }

  _createClass(Toast, null, [{
    key: "Success",
    value: function () {
      var _Success = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(msg) {
        var options,
            key,
            ins,
            canClose,
            _args = arguments;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {
                  style: {
                    right: 'unset'
                  }
                };
                key = (0, _uuid["default"])();
                _context.next = 4;
                return getInstance();

              case 4:
                ins = _context.sent;
                canClose = options.canClose !== undefined ? options.canClose : false;
                ins.notice({
                  content: (0, _SuccessRender.RenderSuccess)(msg, key, canClose, ins),
                  style: options.style,
                  duration: options.duration || canClose === false ? 3 : 3000,
                  key: key
                });

              case 7:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      function Success(_x) {
        return _Success.apply(this, arguments);
      }

      return Success;
    }()
  }, {
    key: "Warning",
    value: function () {
      var _Warning = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(msg) {
        var options,
            key,
            ins,
            canClose,
            _args2 = arguments;
        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
                  style: {
                    right: 'unset'
                  }
                };
                key = (0, _uuid["default"])();
                _context2.next = 4;
                return getInstance();

              case 4:
                ins = _context2.sent;
                canClose = options.canClose !== undefined ? options.canClose : false;
                ins.notice({
                  content: (0, _SuccessRender.RenderWarning)(msg, key, canClose, ins),
                  style: options.style,
                  duration: options.duration || canClose === false ? 3 : 3000,
                  key: key
                });

              case 7:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2);
      }));

      function Warning(_x2) {
        return _Warning.apply(this, arguments);
      }

      return Warning;
    }()
  }, {
    key: "Error",
    value: function () {
      var _Error = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(msg) {
        var options,
            key,
            ins,
            canClose,
            _args3 = arguments;
        return regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {
                  style: {
                    right: 'unset'
                  }
                };
                key = (0, _uuid["default"])();
                _context3.next = 4;
                return getInstance();

              case 4:
                ins = _context3.sent;
                canClose = options.canClose !== undefined ? options.canClose : false;
                ins.notice({
                  content: (0, _SuccessRender.RenderError)(msg, key, canClose, ins),
                  style: options.style,
                  duration: options.duration || canClose === false ? 3 : 3000,
                  key: key
                });

              case 7:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3);
      }));

      function Error(_x3) {
        return _Error.apply(this, arguments);
      }

      return Error;
    }()
  }]);

  return Toast;
}();

var _default = Toast;
exports["default"] = _default;