import { createStore } from '@stencil/store';
import { initialState } from './notifications.store';
class NotificationsService {
  constructor() {
    const { state } = createStore(initialState);
    this._state = state;
  }
  get state() {
    return this._state;
  }
  closeCurrent() {
    const items = [...this._state.items];
    items.shift();
    this._state.items = items;
  }
  clearNotifications() {
    this._state.items = [];
  }
  showErrorNotification(details, priority) {
    this.pushNotification(details, priority !== null && priority !== void 0 ? priority : 0, 'danger');
  }
  showInfoNotification(details, priority) {
    this.pushNotification(details, priority !== null && priority !== void 0 ? priority : 0, 'info');
  }
  showWarningNotification(details, priority) {
    this.pushNotification(details, priority !== null && priority !== void 0 ? priority : 0, 'warning');
  }
  showSuccessNotification(details, priority) {
    this.pushNotification(details, priority !== null && priority !== void 0 ? priority : 0, 'success');
  }
  pushNotification(details, priority, type) {
    const items = [...this._state.items];
    items.push({ details, type, priority });
    this._state.items = items.sort((a, b) => b.priority - a.priority);
  }
}
export default new NotificationsService();
