'use strict';

const changeManager = require('./change-manager-72f643de.js');
const observer = require('./observer-f49483e8.js');
const domNodeSubjectFactory = require('./dom-node-subject-factory-36b5fdbc.js');

/**
 * The function `domAcceptableHandle` always returns `true`.
 *
 * @returns {boolean} true
 */
const domAcceptableHandle = () => {
  return true;
};
/** The `DomNodeSubjectObserverFactory` class provides methods to add and remove observers to HTML element nodes. */
class DomNodeSubjectObserverFactory {
  /**
   * add observer to a given HTML element node
   *
   * @param {HTMLElement} node the node ref
   * @param {VegaEventIDInterface} eventId The `eventId` parameter is of type `VegaEventIDInterface`. It represents the ID of a Vega event.
   * @param {(input?: unknown) => void} callback the callback handle
   * @param {(input?: unknown) => boolean} acceptableHandle the acceptable handle
   */
  static addUniqueObserverToNode(node, eventId, callback, acceptableHandle) {
    if (node) {
      const domNodesObserver = new observer.Observer(typeof acceptableHandle === 'function' ? acceptableHandle.bind(null) : domAcceptableHandle, callback);
      DomNodeSubjectObserverFactory.removeUniqueObserverFromNode(node, eventId);
      changeManager.ChangeManager.register(domNodeSubjectFactory.domNodeSubjectFactory.getSubject(node, eventId), domNodesObserver);
    }
  }
  /**
   * The function removes observers from a given HTML element node.
   *
   * @param {HTMLElement} node - The `node` parameter is an `HTMLElement` object representing an HTML element in the DOM (Document Object Model).
   * @param {VegaEventIDInterface} eventId The `eventId` parameter is of type `VegaEventIDInterface`. It represents the ID of a Vega event.
   */
  static removeUniqueObserverFromNode(node, eventId) {
    if (domNodeSubjectFactory.domNodeSubjectFactory.isExist(node, eventId)) {
      changeManager.ChangeManager.clearObserversBySubject(domNodeSubjectFactory.domNodeSubjectFactory.getSubject(node, eventId));
    }
  }
}

exports.DomNodeSubjectObserverFactory = DomNodeSubjectObserverFactory;
