import { VEGA_COMPONENT_EVENT_MAP } from './event-id/component-event-id-map';
import jqueryDelegatedStrategyController from './event-delegated/jquery-delegated-strategy-controller';
/**
 * The `InternalVegaEventManager` class manages event semantics configuration for global and
 * component-specific settings.
 */
class InternalVegaEventManager {
  constructor() {
    this.config = {};
    this.defaultEventSemantics = {
      namespace: 'vega',
    };
  }
  /**
   * The function sets the semantics configuration for events.
   *
   * @param {EventSemanticsConfig} config - The `config` parameter is of type `EventSemanticsConfig`.
   */
  setSemantics(config) {
    this.config = config;
    jqueryDelegatedStrategyController.updateRegistryFromEventSemantics(config);
  }
  /**
   * The function `getSemantics` returns the event semantics either from the global scope or from the
   * components within a given host element.
   *
   * @param {HTMLElement} host - The host parameter is an HTMLElement that represents the element on
   * which the event semantics are being checked.
   * @returns {EventSemantics} The method `getSemantics` returns a value of type `Nullable<EventSemantics>`.
   */
  getSemantics(host) {
    return Object.assign({}, this.defaultEventSemantics, this.getSemanticsInGlobal(), this.getSemanticsInComponents(host));
  }
  /**
   * The function "getEnabledEventIdsByComponent" returns an array of event Ids associated with a given component
   * name.
   *
   * @param {VegaComponentName} componentName - The `componentName` parameter is a string that represents
   * the name of a Vega component.
   * @returns {Nullable<VegaEventID[]>} a nullable array of VegaEventID objects.
   */
  getEnabledEventIdsByComponent(componentName) {
    return VEGA_COMPONENT_EVENT_MAP.get(componentName);
  }
  /**
   * The function `getSemanticsInGlobal` returns the global event semantics configuration.
   *
   * @returns {Nullable<EventSemantics>} The method is returning a nullable EventSemantics object.
   */
  getSemanticsInGlobal() {
    return this.config.global;
  }
  /**
   * The function `getSemanticsInComponents` returns the semantic configuration for a given component
   * based on its host element.
   *
   * @param {HTMLElement} host - The `host` parameter is an HTMLElement that represents the component for
   * which we want to retrieve the semantics.
   * @returns {Nullable<EventSemantics>} a value of type `Nullable<EventSemantics>`.
   */
  getSemanticsInComponents(host) {
    const componentName = host.tagName.toLocaleLowerCase();
    if (this.config.components &&
      Object.prototype.hasOwnProperty.call(this.config.components, componentName)) {
      return this.config.components[componentName];
    }
    return null;
  }
}
export default new InternalVegaEventManager();
