import { I as InternalVegaZIndexManager } from './internal-vega-z-index-manager-b6b79599.js';
import { g as generateUUID } from './misc-9fdbcfbb.js';
import { g as getDeviceType, D as DeviceType } from './ui-6dd51115.js';
import './global-slimmer-registry-0a7aa308.js';
import { I as InjectVegaSlimmer } from './inject-vega-slimmer-caffc2aa.js';
import { I as InjectVegaTelemetrySlimmer, c as createPublicAPIRuntimeMetricsSlimmer } from './create-public-api-runtime-metrics-slimmer-407de188.js';
import { c as createDynamicSlimmer } from './dynamic-slimmer-60d5da5a.js';
import { P as PageResizeObserverSlimmer } from './page-resize-observer-slimmer-558308bc.js';
import './number-4398f2e1.js';
import './breakpoints-332702ed.js';
import './ui-93922c59.js';
import './breakpoints-d9faf11c.js';
import './try-get-document-bef0f526.js';

const VegaNotifyRuntimeMetricsPayloadDefinition = [
  {
    payloadKey: 'IS_OPEN_METHOD_CALLED',
    payloadDescription: 'Indicate if the method open of public API VegaNotifyController is called',
    /**
     * Indicate whether the method is collected when the method been called .
     *
     * @param {string} scope - The class name of public api
     * @param {string} methodName - The method name called by the public api
     * @returns {boolean} A boolean value
     */
    canAccept: (scope, methodName) => scope === 'VegaNotifyController' && methodName === 'open',
    /**
     * The function checks if the method name is open.
     *
     * @returns {boolean} A boolean value
     */
    payloadValue: () => {
      return true;
    },
  },
  {
    payloadKey: 'IS_CLOSE_METHOD_CALLED',
    payloadDescription: 'Indicate if the method close of public API VegaNotifyController is called',
    /**
     * Indicate whether the method is collected when the method been called .
     *
     * @param {string} scope - The class name of public api
     * @param {string} methodName - The method name called by the public api
     * @returns {boolean} A boolean value
     */
    canAccept: (scope, methodName) => scope === 'VegaNotifyController' && methodName === 'close',
    /**
     * The function checks if the method name is close.
     *
     * @returns {boolean} A boolean value
     */
    payloadValue: () => {
      return true;
    },
  },
  {
    payloadKey: 'IS_CLOSEALL_METHOD_CALLED',
    payloadDescription: 'Indicate if the method closeAll of public API VegaNotifyController is called',
    /**
     * Indicate whether the method is collected when the method been called .
     *
     * @param {string} scope - The class name of public api
     * @param {string} methodName - The method name called by the public api
     * @returns {boolean} A boolean value
     */
    canAccept: (scope, methodName) => scope === 'VegaNotifyController' && methodName === 'closeAll',
    /**
     * The function checks if the method name is closeAll.
     *
     * @returns {boolean} A boolean value
     */
    payloadValue: () => {
      return true;
    },
  },
];

var __decorate = (undefined && undefined.__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;
};
/**
 * The page notification controller
 */
class VegaNotifyController {
  constructor() {
    this.resizeObserverSlimmer = createDynamicSlimmer(VegaNotifyController, PageResizeObserverSlimmer, [], [{ mapFrom: 'connectResizeObserver', mapTo: 'connectResizeObserver' }], [
      {
        // eslint-disable-next-line jsdoc/require-jsdoc
        callback: (entries) => {
          var _a;
          const currentVisible = entries[0].contentRect.height > 0;
          if (!currentVisible && ((_a = this.container) === null || _a === void 0 ? void 0 : _a.classList.contains('hydrated'))) {
            InternalVegaZIndexManager.removeZIndex(this.container, 'top');
            this.container.remove();
            this.container = null;
          }
        },
        // eslint-disable-next-line jsdoc/require-jsdoc
        target: () => this.container,
      },
    ]);
    this.vegaPublicAPIRuntimeMetricsSlimmer = createPublicAPIRuntimeMetricsSlimmer(VegaNotifyController, ['open', 'close', 'closeAll'], VegaNotifyRuntimeMetricsPayloadDefinition);
  }
  /**
   * It creates a new notification element, adds it to the container, and returns the notification's ID
   *
   * @param {VegaNotifyOption} options - VegaNotifyProps
   * @returns {Promise<string>} The ID of the notification.
   * @vegaVersion 1.17.0
   */
  async open(options) {
    const pageNotification = this.createPageNotification(options);
    this.getContainer().append(pageNotification);
    return pageNotification.id;
  }
  /**
   * It closes all notifications
   *
   * @vegaVersion 1.17.0
   */
  async closeAll() {
    this.container &&
      Array.from(this.container.children).forEach((item) => {
        void item.close();
      });
  }
  /**
   * It closes the notification with the given id
   *
   * @param {string} id - The id of the notification to close.
   * @vegaVersion 1.17.0
   */
  async close(id) {
    // eslint-disable-next-line no-restricted-globals
    await document.getElementById(id).close();
  }
  /**
   * The function "connectResizeObserver" is used to connect a resize observer.
   *
   * @vegaVersion 1.17.0
   */
  connectResizeObserver() {
  }
  /**
   * It creates a new page notification element, sets its properties, and returns it
   *
   * @param {VegaNotifyOption} props - VegaNotifyProps - the properties of the notification
   * @returns {HTMLVegaPageNotificationElement} A function that takes in a props object and returns a pageNotification element.
   */
  createPageNotification(props) {
    const pageNotification = 
    // eslint-disable-next-line no-restricted-globals
    document.createElement('vega-page-notification');
    Object.keys(props).forEach((propName) => {
      props[propName] !== undefined && (pageNotification[propName] = props[propName]);
    });
    pageNotification.style.marginBottom = getDeviceType() === DeviceType.MOBILE ? '12px' : '16px';
    pageNotification.id = `vega-page-notification-${generateUUID()}`;
    return pageNotification;
  }
  /**
   * It creates a div element, sets its z-index to be on top of everything else, adds a class to it, and
   * then adds it to the body of the page
   *
   * @returns {HTMLVegaPageNotificationListElement} The container is being returned.
   */
  getContainer() {
    if (this.container) {
      return this.container;
    }
    // eslint-disable-next-line no-restricted-globals
    this.container = document.createElement('vega-page-notification-list');
    InternalVegaZIndexManager.setZIndex(this.container, 'top');
    if (getDeviceType() === DeviceType.MOBILE) {
      this.container.classList.add('vega-page-notification-list-bottom');
    }
    else {
      this.container.classList.add('vega-page-notification-list-topRight');
    }
    // eslint-disable-next-line no-restricted-globals
    document.body.append(this.container);
    this.connectResizeObserver();
    return this.container;
  }
}
__decorate([
  InjectVegaSlimmer()
], VegaNotifyController.prototype, "resizeObserverSlimmer", void 0);
__decorate([
  InjectVegaTelemetrySlimmer()
], VegaNotifyController.prototype, "vegaPublicAPIRuntimeMetricsSlimmer", void 0);
const VegaNotify = new VegaNotifyController();

export { VegaNotify };
