"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "EVENTS", {
  enumerable: true,
  get: function () {
    return _types.EVENTS;
  }
});
exports.NotificationService = void 0;
var _notificationEmmiter = _interopRequireDefault(require("./notification-emmiter"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function showNotification(message, level, options) {
  const notification = {
    ...options,
    message,
    level
  };
  if (options?.retry) {
    notification.title = options.title;
    notification.action = options.retry;
  }
  // Using 'any' since there are no existing type patterns
  _notificationEmmiter.default.emit(_types.EVENTS.NOTIFICATION_SHOW, notification);
}
class NotificationServiceCreator {
  subscribe(event, callback) {
    this.subscriptionCallback = callback;
    _notificationEmmiter.default.on(event, callback);
    return {
      cancel: () => _notificationEmmiter.default.off(event, callback)
    };
  }
  info(message, options) {
    return showNotification(message, _types.NOTIFICATION_LEVEL.INFO, options);
  }
  success(message, options) {
    return showNotification(message, _types.NOTIFICATION_LEVEL.SUCCESS, options);
  }
  warn(message, options) {
    return showNotification(message, _types.NOTIFICATION_LEVEL.WARNING, options);
  }
  error(message, options) {
    return showNotification(message, _types.NOTIFICATION_LEVEL.FAILURE, options);
  }
  block() {
    if (this.subscriptionCallback) {
      _notificationEmmiter.default.off(_types.EVENTS.NOTIFICATION_SHOW, this.subscriptionCallback);
    }
  }
  unblock() {
    if (this.subscriptionCallback) {
      _notificationEmmiter.default.on(_types.EVENTS.NOTIFICATION_SHOW, this.subscriptionCallback);
    }
  }

  /**
   *dismiss all shown notifications at once
   */
  dismissAll() {
    // Using 'any' since there are no existing type patterns
    _notificationEmmiter.default.emit(_types.EVENTS.NOTIFICATIONS_DISMISS_ALL);
  }
}
const NotificationService = exports.NotificationService = new NotificationServiceCreator();