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';
/**
 * Opened modal stack controller
 */
export class VegaModalOpenedModalStackController extends VegaSlimmer {
  /**
   * Adds the current host element to an array in a modal toggle controller.
   */
  push() {
    VegaModalOpenedModalStackController.openedModalStack.push(this.host);
  }
  /**
   * Removes the current modal from the opened modal stack.
   */
  remove() {
    VegaModalOpenedModalStackController.openedModalStack =
      VegaModalOpenedModalStackController.openedModalStack.filter((modal) => modal !== this.host);
  }
  //TODO: Record the nest modal by an array.
  /**
   * Get visible modal length.
   *
   * @returns {number} - Visible modal length.
   */
  length() {
    return VegaModalOpenedModalStackController.openedModalStack.length;
  }
  /**
   * Returns the previous HTMLVegaModalElement from the openedModalStack if it exists.
   *
   * @returns {Nullable<HTMLVegaModalElement>} - The previous HTMLVegaModalElement.
   */
  peek() {
    const length = this.length();
    if (length > 0) {
      return VegaModalOpenedModalStackController.openedModalStack[length - 1];
    }
    /* istanbul ignore next */
    return null;
  }
}
VegaModalOpenedModalStackController.openedModalStack = [];
__decorate([
  MapToComponentField()
], VegaModalOpenedModalStackController.prototype, "host", void 0);
