var __decorate = (this && this.__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;
};
import { MapToComponentField, MapToComponentMethod } from 'vega-slimmer/core';
import { MutationObserverSlimmer } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-slimmer';
import { TagNameMutationFilter } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-filters';
/**
 * Nested modal controller
 */
export class VegaNestedModalController extends MutationObserverSlimmer {
  constructor() {
    super({
      mutationFilter: TagNameMutationFilter('VEGA-MODAL'),
      options: {
        childList: true,
        subtree: true,
      },
      // eslint-disable-next-line jsdoc/require-jsdoc
      callback: () => {
        this.appendNestedModalToBody();
      },
    });
  }
  /**
   * Component lifecycle - [connectedCallback]
   */
  connectedCallback() {
    this.appendNestedModalToBody();
  }
  /**
   * The function appends all nested 'vega-modal' elements found within the host element to the document
   * body.
   */
  appendNestedModalToBody() {
    this.host.querySelectorAll('vega-modal').forEach((modal) => {
      // eslint-disable-next-line no-restricted-globals
      document.body.append(modal);
    });
  }
}
__decorate([
  MapToComponentField()
], VegaNestedModalController.prototype, "host", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaNestedModalController.prototype, "connectedCallback", null);
