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 internalVegaZIndexManager from '../../../../helpers/zindex/internal-vega-z-index-manager';
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/** The ManageVegaLoaderWrapperZIndex class manages z-index of the vega-loader-wrapper. */
export class ManageVegaLoaderWrapperZIndexController extends VegaSlimmer {
  /**
   * When vega loader wrapper is connected
   */
  connectedCallback() {
    this.setIndex();
  }
  /**
   * When vega loader wrapper is disconnected
   */
  disconnectedCallback() {
    this.removeIndex();
  }
  /**
   * Sets the z-index level for the vega-loader-wrapper based on the target container.
   */
  setIndex() {
    // eslint-disable-next-line no-restricted-globals
    const containerElement = document.querySelector(this.host.dataset.container);
    if (containerElement) {
      if (containerElement.tagName === 'BODY') {
        internalVegaZIndexManager.setZIndex(this.host, 'base');
      }
    }
  }
  /**
   * Removes the z-index of the vega-loader-wrapper by resetting it.
   */
  removeIndex() {
    internalVegaZIndexManager.removeZIndex(this.host, 'base');
  }
}
__decorate([
  MapToComponentField()
], ManageVegaLoaderWrapperZIndexController.prototype, "host", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], ManageVegaLoaderWrapperZIndexController.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], ManageVegaLoaderWrapperZIndexController.prototype, "disconnectedCallback", null);
