'use strict';

function getEventHandlerFromArguments(args) {
  var arg0;
  if (args && args.length) {
    arg0 = args[0];
  }
  if (typeof arg0 === "function") {
    return arg0;
  }
  return null;
}
class EventEmitter {
  _events;
  constructor() {
    this._events = {};
  }
  resolveEvent(eventName) {
    var event = this._events[eventName];
    if (!event) {
      this._events[eventName] = event = new Event(eventName);
    }
    return event;
  }
  on(eventName, handler) {
    this.resolveEvent(eventName).on(handler);
  }
  trigger(eventName, args) {
    this.resolveEvent(eventName).trigger(args);
  }
}
class Event {
  _callbacks;
  _eventName;
  constructor(eventName) {
    this._callbacks = [];
    this._eventName = eventName;
  }
  on(callback) {
    this._callbacks.push(callback);
  }
  trigger(args) {
    const eventName = this._eventName;
    this._callbacks.forEach(function(callback) {
      callback.apply(null, [eventName, ...args]);
    });
  }
}
class NotificationService {
  _eventEmitter;
  constructor() {
    this._eventEmitter = new EventEmitter();
  }
  eventFactory(event, args) {
    var handler = getEventHandlerFromArguments(args);
    if (handler) {
      this._eventEmitter.on(event, handler);
    } else {
      this._eventEmitter.trigger(event, args);
    }
    return this;
  }
  Events = {
    GET_DOCUMENT_MAP_STATE: "trv.GET_DOCUMENT_MAP_STATE",
    SET_DOCUMENT_MAP_VISIBLE: "trv.SET_DOCUMENT_MAP_VISIBLE",
    GET_PARAMETER_AREA_STATE: "trv.GET_PARAMETER_AREA_STATE",
    SET_PARAMETER_AREA_VISIBLE: "trv.SET_PARAMETER_AREA_VISIBLE",
    SET_TOGGLE_SIDE_MENU: "trv.SET_TOGGLE_SIDE_MENU",
    GET_TOGGLE_SIDE_MENU: "trv.GET_TOGGLE_SIDE_MENU",
    UPDATE_UI: "trv.UPDATE_UI",
    CSS_LOADED: "trv.CSS_LOADED",
    UPDATE_UI_INTERNAL: "trv.UPDATE_UI_INTERNAL",
    PAGE_NUMBER: "trv.PAGE_NUMBER",
    PAGE_COUNT: "trv.PAGE_COUNT",
    GET_SEARCH_DIALOG_STATE: "trv.GET_SEARCH_DIALOG_STATE",
    GET_SEND_EMAIL_DIALOG_STATE: "trv.GET_SEND_EMAIL_DIALOG_STATE",
    SET_SEARCH_DIALOG_VISIBLE: "trv.SET_SEARCH_DIALOG_VISIBLE",
    SET_SEND_EMAIL_DIALOG_VISIBLE: "trv.SET_SEND_EMAIL_DIALOG_VISIBLE",
    SET_AI_PROMPT_DIALOG_VISIBLE: "trv.SET_AI_PROMPT_DIALOG_VISIBLE"
  };
  on() {
    const eventEmitter = this._eventEmitter;
    eventEmitter.on.apply(eventEmitter, arguments);
  }
  getDocumentMapState() {
    return this.eventFactory(this.Events.GET_DOCUMENT_MAP_STATE, arguments);
  }
  setDocumentMapVisible() {
    return this.eventFactory(this.Events.SET_DOCUMENT_MAP_VISIBLE, arguments);
  }
  getParametersAreaState() {
    return this.eventFactory(this.Events.GET_PARAMETER_AREA_STATE, arguments);
  }
  setParametersAreaVisible() {
    return this.eventFactory(this.Events.SET_PARAMETER_AREA_VISIBLE, arguments);
  }
  cssLoaded() {
    return this.eventFactory(this.Events.CSS_LOADED, arguments);
  }
  updateUI() {
    return this.eventFactory(this.Events.UPDATE_UI, arguments);
  }
  updateUIInternal() {
    return this.eventFactory(this.Events.UPDATE_UI_INTERNAL, arguments);
  }
  pageNumberChange() {
    return this.eventFactory(this.Events.PAGE_NUMBER, arguments);
  }
  pageCountChange() {
    return this.eventFactory(this.Events.PAGE_COUNT, arguments);
  }
  getSendEmailDialogState() {
    return this.eventFactory(this.Events.GET_SEND_EMAIL_DIALOG_STATE, arguments);
  }
  setSearchDialogVisible() {
    return this.eventFactory(this.Events.SET_SEARCH_DIALOG_VISIBLE, arguments);
  }
  setSendEmailDialogVisible() {
    return this.eventFactory(this.Events.SET_SEND_EMAIL_DIALOG_VISIBLE, arguments);
  }
  setAiPromptDialogVisible() {
    return this.eventFactory(this.Events.SET_AI_PROMPT_DIALOG_VISIBLE, arguments);
  }
}

exports.NotificationService = NotificationService;
