"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
module.exports = exports.OverlayController = void 0;
var _vue = require("vue");
const OverlayController = exports.OverlayController = {
  instances: {},
  stack: [],
  zIndex: 1050,
  register(instance) {
    const name = (0, _vue.unref)(instance.name);
    if (name) {
      OverlayController.instances[name] = instance;
    }
  },
  unregister(instance) {
    const name = (0, _vue.unref)(instance.name);
    if (name) {
      OverlayController.instances[name] = null;
      delete OverlayController.instances[name];
    }
  },
  open(name) {
    if (typeof window === "undefined") {
      return;
    }
    OverlayController.stack.push(name);
    const element = (0, _vue.unref)(OverlayController.instances[name].elementRef);
    if (element) {
      element.style.zIndex = OverlayController.zIndex++;
    }
  },
  close(name) {
    if (typeof window === "undefined") {
      return;
    }
    OverlayController.stack.splice(OverlayController.stack.indexOf(name), 1);
  },
  getTopOverlay() {
    const topOverlayName = OverlayController.stack.slice(-1)[0] || "";
    return OverlayController.instances[topOverlayName];
  },
  onPressEscape() {
    const topOverlay = OverlayController.getTopOverlay();
    if (topOverlay && topOverlay.closeOnPressEscape) {
      topOverlay.hide();
    }
  }
};
var _default = exports.default = OverlayController;