"use strict";

exports.__esModule = true;
exports.success = exports.show = exports.notice = exports.loading = exports.hide = exports.help = exports.error = void 0;
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _render = require("../utils/render");
var _message = _interopRequireDefault(require("./message"));
var _view = _interopRequireDefault(require("../view"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var hideCurrent = null;
var hide = function () {
  if (hideCurrent) {
    hideCurrent();
  }
  hideCurrent = null;
};
exports.hide = hide;
var show = function (options) {
  var _options$shape = options.shape,
    shape = _options$shape === void 0 ? 'toast' : _options$shape,
    _options$prefix = options.prefix,
    prefix = _options$prefix === void 0 ? 'mt-' : _options$prefix,
    _options$duration = options.duration,
    duration = _options$duration === void 0 ? 1500 : _options$duration,
    content = options.content,
    type = options.type,
    onClose = options.onClose,
    other = (0, _tslib.__rest)(options, ["shape", "prefix", "duration", "content", "type", "onClose"]);
  hide();
  var hideThis = (0, _render.renderToRoot)( /*#__PURE__*/(0, _react.createElement)(_view.default, {
    "disable-scroll": true
  }, /*#__PURE__*/(0, _react.createElement)(_message.default, _extends({
    visible: true,
    shape: shape,
    type: type
  }, other), content), /*#__PURE__*/(0, _react.createElement)(_view.default, {
    "disable-scroll": true,
    className: prefix + "message" + "-mask"
  })), onClose);
  hideCurrent = hideThis;
  if (duration > 0) {
    if (type === 'loading' && !('duration' in options)) {
      return hideThis;
    }
    setTimeout(function () {
      hideThis();
      if (hideCurrent === hideThis) {
        hideCurrent = null;
      }
    }, duration);
  }
  return hideThis;
};
exports.show = show;
var handleFastCall = function (type, options) {
  var opts;
  if ((0, _utils.isString)(options)) {
    opts = {
      title: options
    };
  } else {
    opts = options;
  }
  return show(Object.assign(Object.assign({}, opts), {
    type: type
  }));
};
var success = handleFastCall.bind(null, 'success');
exports.success = success;
var error = handleFastCall.bind(null, 'error');
exports.error = error;
var notice = handleFastCall.bind(null, 'notice');
exports.notice = notice;
var help = handleFastCall.bind(null, 'help');
exports.help = help;
var loading = handleFastCall.bind(null, 'loading');
exports.loading = loading;