import {MouseEventNode} from "../../../nodes/event/Mouse";
import {PointerEventNode} from "../../../nodes/event/Pointer";
import {SceneEventNode} from "../../../nodes/event/Scene";
import {KeyboardEventNode} from "../../../nodes/event/Keyboard";
import {SceneEventsController as SceneEventsController2} from "./SceneEventsController";
import {KeyboardEventsController as KeyboardEventsController2} from "./KeyboardEventsController";
import {MouseEventsController as MouseEventsController2} from "./MouseEventsController";
import {PointerEventsController as PointerEventsController2} from "./PointerEventsController";
export class SceneEventsDispatcher {
  constructor(scene) {
    this.scene = scene;
    this._controllers = [];
  }
  registerEventNode(node) {
    const controller = this._find_or_create_controller_for_node(node);
    if (controller) {
      controller.registerNode(node);
    }
  }
  unregisterEventNode(node) {
    const controller = this._find_or_create_controller_for_node(node);
    if (controller) {
      controller.unregisterNode(node);
    }
  }
  updateViewerEventListeners(node) {
    const controller = this._find_or_create_controller_for_node(node);
    if (controller) {
      controller.updateViewerEventListeners();
    }
  }
  traverseControllers(callback) {
    for (let controller of this._controllers) {
      callback(controller);
    }
  }
  _find_or_create_controller_for_node(node) {
    switch (node.type()) {
      case KeyboardEventNode.type():
        return this.keyboardEventsController;
      case MouseEventNode.type():
        return this.mouseEventsController;
      case PointerEventNode.type():
        return this.pointerEventsController;
      case SceneEventNode.type():
        return this.sceneEventsController;
    }
  }
  get keyboardEventsController() {
    return this._keyboard_events_controller = this._keyboard_events_controller || this._create_controller(KeyboardEventsController2);
  }
  get mouseEventsController() {
    return this._mouse_events_controller = this._mouse_events_controller || this._create_controller(MouseEventsController2);
  }
  get pointerEventsController() {
    return this._pointer_events_controller = this._pointer_events_controller || this._create_controller(PointerEventsController2);
  }
  get sceneEventsController() {
    return this._scene_events_controller = this._scene_events_controller || this._create_controller(SceneEventsController2);
  }
  _create_controller(event_constructor) {
    const controller = new event_constructor(this);
    if (!this._controllers.includes(controller)) {
      this._controllers.push(controller);
    }
    return controller;
  }
}
