"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _beeNotification = _interopRequireDefault(require("bee-notification"));

var _beeIcon = _interopRequireDefault(require("bee-icon"));

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

var defaultDuration = 4.5;

function noop() {}

function unDefined(target) {
  return target === undefined;
}

var instance = {};

function notice(args) {
  var description = args.description,
      position = args.position,
      duration = args.duration,
      icon = args.icon,
      container = args.container,
      serviceCode = args.serviceCode,
      className = args.className;
  var message = args.message;

  if (instance[serviceCode] == null) {
    _beeNotification["default"].newInstance({
      position: position,
      container: container,
      className: className
    }, function (n) {
      if (icon) {
        message = /*#__PURE__*/_react["default"].createElement("div", {
          className: "notification-icon-title"
        }, icon, /*#__PURE__*/_react["default"].createElement("span", null, message));
      }

      instance[serviceCode] = n;
      instance[serviceCode].notice({
        title: message,
        content: description,
        color: 'light',
        duration: duration,
        onClose: args.onClose ? args.onClose : noop
      });
    });
  } else {
    instance[serviceCode].notice({
      title: message,
      content: description,
      color: 'light',
      duration: duration,
      onClose: args.onClose ? args.onClose : noop
    });
  }
}

var api = {
  config: function config(options) {},
  close: function close(key) {
    instance[serviceCode] && instance[serviceCode].remove(key);
  },
  notice: notice
};
['open', 'success', 'info', 'warning', 'error'].forEach(function (type) {
  api[type] = function (_ref) {
    var duration = _ref.duration,
        message = _ref.message,
        description = _ref.description,
        placement = _ref.placement,
        icon = _ref.icon,
        style = _ref.style,
        container = _ref.container,
        _ref$serviceCode = _ref.serviceCode,
        serviceCode = _ref$serviceCode === void 0 ? 'notification' : _ref$serviceCode,
        className = _ref.className;

    switch (type) {
      case 'info':
        icon = /*#__PURE__*/_react["default"].createElement(_beeIcon["default"], {
          type: "uf-i"
        });
        break;

      case 'error':
        icon = /*#__PURE__*/_react["default"].createElement(_beeIcon["default"], {
          type: "uf-close"
        });
        break;

      case 'warning':
        icon = /*#__PURE__*/_react["default"].createElement(_beeIcon["default"], {
          type: "uf-exc"
        });
        break;

      case 'success':
        icon = /*#__PURE__*/_react["default"].createElement(_beeIcon["default"], {
          type: "uf-correct"
        });
        break;

      default:
        break;
    }

    return api.notice({
      duration: unDefined(duration) ? defaultDuration : duration,
      position: placement || 'topRight',
      message: message,
      icon: icon,
      description: description,
      container: container,
      serviceCode: serviceCode,
      className: className
    });
  };
});
var _default = api;
exports["default"] = _default;
//# sourceMappingURL=Notification.js.map
