import { c as MapToComponentField, M as MapToComponentMethod, V as VegaSlimmer } from './global-slimmer-registry-17c4efd4.js';

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
 * The `MutationObserverSlimmer` class in TypeScript extends `VegaSlimmer` and implements a
 * simplified version of `MutationObserver` functionality for observing DOM mutations.
 */
class MutationObserverSlimmer extends VegaSlimmer {
  /**
   * The constructor initializes a class instance with a MutationObserverEntry parameter.
   *
   * @param {MutationObserverEntry} observerEntry - The `observerEntry` parameter in the constructor is
   * of type `MutationObserverEntry`. This parameter likely contains information about a single change
   * that was observed by a `MutationObserver` instance. It could include details such as the type of
   * mutation, the target element that was mutated, and any additional relevant information
   */
  constructor(observerEntry) {
    super();
    this.mutationObserver = null;
    this.observerEntry = observerEntry;
  }
  /**
   * Component lifecycle - [connectedCallback]
   */
  connectedCallback() {
    if (this.mutationObserver) {
      this.observeMutationObserver();
    }
  }
  /**
   * Component lifecycle - [disconnectedCallback]
   */
  disconnectedCallback() {
    if (this.mutationObserver) {
      this.mutationObserver.disconnect();
    }
  }
  /**
   * Component lifecycle - [componentDidLoad]
   */
  componentDidLoad() {
    this.initMutationObserver();
    this.observeMutationObserver();
  }
  /**
   * The function `initMutationObserver` creates a new MutationObserver that triggers a callback based on
   * specified mutation filters.
   */
  initMutationObserver() {
    this.mutationObserver = new MutationObserver(async (mutations) => {
      if (!this.observerEntry.mutationFilter ||
        this.observerEntry.mutationFilter(mutations, this.host)) {
        this.observerEntry.callback(mutations);
      }
    });
  }
  /**
   * The function observeMutationObserver() observes mutations on a target element using a
   * MutationObserver.
   */
  observeMutationObserver() {
    const target = this.observerEntry.target ? this.observerEntry.target() : this.host;
    if (target && this.mutationObserver) {
      this.mutationObserver.observe(target, this.observerEntry.options);
    }
  }
}
__decorate([
  MapToComponentField()
], MutationObserverSlimmer.prototype, "host", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], MutationObserverSlimmer.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], MutationObserverSlimmer.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentDidLoad')
], MutationObserverSlimmer.prototype, "componentDidLoad", null);

export { MutationObserverSlimmer as M };
