import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import { O as Observer } from './observer-3959f9dd.js';

/**
 * The `RemoteInvocationRegistry` provides methods for performing remote invocation calls
 * and registering remote invocation handlers.
 */
class RemoteInvocationRegistry {
  /**
   * This function performs a remote invocation call and returning the result.
   *
   * @typedef T generic type
   * @param {HTMLElement} subject the dom node subject
   * @param {unknown[]} args - The `args` parameter of specific method.
   * @returns {Nullable<T>} The result of call `remoteInvocation`.
   */
  call(subject, ...args) {
    let result = null;
    ChangeManager.notify(subject, {
      args,
      resultCallback: 
      /* eslint-disable jsdoc/require-jsdoc */
      (response) => {
        result = response;
      },
    });
    return result;
  }
  /**
   * The function registers a remote invocation handler.
   *
   * @param {HTMLElement} subject the dom node subject
   * @param {Function}remoteInvocationHandler - The method that is ultimately called.
   */
  register(subject, remoteInvocationHandler) {
    const observer = new Observer(this.isAcceptableObserver.bind(this), (payload) => {
      const result = remoteInvocationHandler(...payload.args);
      payload.resultCallback(result);
    });
    ChangeManager.register(subject, observer);
  }
  /**
   * The function un-registers a remote invocation call handler.
   *
   * @param {HTMLElement} subject the dom node subject
   */
  unRegister(subject) {
    ChangeManager.clearObserversBySubject(subject);
  }
  /**
   * The function isAcceptableObserver checks if the input matches a specified type T.
   *
   * @param {unknown} _input - The `_input` parameter is of type `unknown`, which means it can hold any
   * value.
   * @returns {boolean} The `isAcceptableObserver` function is returning `true`.
   */
  isAcceptableObserver(_input) {
    return true;
  }
}
const remoteInvocationRegistry = new RemoteInvocationRegistry();

export { remoteInvocationRegistry as r };
