import { V as VegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { c as createDynamicSlimmer } from './dynamic-slimmer-90b8af32.js';
import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import { O as Observer } from './observer-3959f9dd.js';
import { k as VegaInternalSubStatePull, j as VegaInternalSubStatePush } from './vega-internal-event-id-db974a0d.js';
import { d as domNodeSubjectFactory } from './dom-node-subject-observer-factory-3897e95b.js';

/**
 * Sub state notify slimmer
 */
class SubStateNotifySlimmerBase extends VegaSlimmer {
  // eslint-disable-next-line jsdoc/require-jsdoc
  constructor({ propName }) {
    super();
    /**
     * Checks if the input `host` matches the current `host` and `stateName` matches the current `propName`.
     *
     * @param {unknown} input - The `input` parameter is of type `unknown`, which means it can be any type.
     * @returns {boolean} a boolean value indicating whether the input is an acceptable table observer.
     */
    this.isAcceptableObserverPayload = (input) => {
      return input.host === this.host && input.stateName === this.propName;
    };
    this.propName = propName;
  }
  /**
   * Register the observer in connectedCallback
   */
  connectedCallback() {
    this.subStateObserver = new Observer(this.isAcceptableObserverPayload.bind(this), (payload) => {
      payload.callback(this.propValue);
    });
    ChangeManager.register(domNodeSubjectFactory.getSubject(this.host, VegaInternalSubStatePull), this.subStateObserver);
  }
  /**
   * unregister the observer in disconnectedCallback
   */
  disconnectedCallback() {
    ChangeManager.unregister(domNodeSubjectFactory.getSubject(this.host, VegaInternalSubStatePull), this.subStateObserver);
  }
  /**
   * Notify the children component which prop has been changed in the parent component
   */
  subStateNotify() {
    ChangeManager.notify(domNodeSubjectFactory.getSubject(this.host, VegaInternalSubStatePush), {
      host: this.host,
      stateName: this.propName,
      value: this.propValue,
    });
  }
}

/**
 * Create dynamic subState notify slimmer
 *
 * @param {ClassPrototype} mapFromClass - It represents the class that you want to map from.
 * @param {string} propName - The parent component prop name
 * @param {string} watchMethodName - The watch method name of prop change
 * @returns {SubStateNotifySlimmerBase} - SubState notify slimmer
 */
function createSubStateNotifySlimmer(mapFromClass, propName, watchMethodName) {
  const methodsMap = [
    { mapFrom: 'connectedCallback', mapTo: 'connectedCallback' },
    { mapFrom: 'disconnectedCallback', mapTo: 'disconnectedCallback' },
  ];
  if (watchMethodName) {
    methodsMap.push({ mapFrom: watchMethodName, mapTo: 'subStateNotify' });
  }
  return createDynamicSlimmer(mapFromClass, SubStateNotifySlimmerBase, [
    { mapFrom: 'host', mapTo: 'host' },
    { mapFrom: propName, mapTo: 'propValue' },
  ], methodsMap, [
    {
      propName: propName,
    },
  ]);
}

export { createSubStateNotifySlimmer as c };
