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, VegaSlimmer } from 'vega-slimmer/core';
/**
 * Modal backdrop controller
 */
export class VegaModalBackdropController extends VegaSlimmer {
  /**
   * Get the backdropRef element or null.
   *
   * @returns {HTMLElement | null} - The backdropRef.
   */
  getBackdropRef() {
    return this.backdropRef;
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-modal-backdrop-color-default-e2e}
   * @see{module:vega-modal-backdrop-color-semi-e2e}
   * @see{module:vega-modal-backdrop-color-none-e2e}
   * @see{module:vega-modal-default-e2e}
   */
  /* istanbul ignore next */
  /**
   * Set backdrop of modal.
   */
  setBackdrop() {
    if (this.backdrop === 'none')
      return;
    // eslint-disable-next-line no-restricted-globals
    let backdrop = document.querySelector('vega-backdrop.modal-backdrop');
    if (!backdrop) {
      // eslint-disable-next-line no-restricted-globals
      backdrop = document.createElement('vega-backdrop');
      backdrop.classList.add('modal-backdrop');
      backdrop.color = VegaModalBackdropController.backdropColorMap[this.backdropColor];
      backdrop.visible = true;
      // eslint-disable-next-line no-restricted-globals
      document.querySelector('body').append(backdrop);
    }
    this.backdropRef = backdrop;
  }
  /**
   * Removes the backdrop element if it exists.
   */
  removeBackdrop() {
    this.backdropRef && this.backdropRef.remove();
  }
}
VegaModalBackdropController.backdropColorMap = {
  default: 'bg-backdrop-modal',
  semi: 'bg-backdrop-popover',
  none: 'bg-transparent',
};
__decorate([
  MapToComponentField()
], VegaModalBackdropController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaModalBackdropController.prototype, "backdrop", void 0);
__decorate([
  MapToComponentField()
], VegaModalBackdropController.prototype, "backdropColor", void 0);
