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;
};
var __rest = (this && this.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
import { generateUUID } from '../../utils/misc';
import { InjectVegaTelemetrySlimmer } from 'vega-slimmer/core';
import { createPublicAPIRuntimeMetricsSlimmer } from '../slimmers/runtime-metrics/create-public-api-runtime-metrics-slimmer';
import { VegaDialogRuntimeMetricsPayloadDefinition } from '../../constants/runtime-metrics-payload-definition/public-api/VegaDialogController/runtime-metrics-payload-definition';
/**
 * The dialog controller
 */
class VegaDialogController {
  constructor() {
    this.vegaPublicAPIRuntimeMetricsSlimmer = createPublicAPIRuntimeMetricsSlimmer(VegaDialogController, ['open'], VegaDialogRuntimeMetricsPayloadDefinition);
  }
  /**
   *
   * It creates a new `vega-dialog` element, sets its properties, appends it to the DOM, and opens it
   *
   * @param {VegaDialogOption} options - VegaDialogOption
   * @returns {HTMLVegaDialogElement} The dialog reference.
   * @vegaVersion 1.24.0
   */
  open(options) {
    // eslint-disable-next-line no-restricted-globals
    const dialog = document.createElement('vega-dialog');
    const { isVerticallyCenter, isVerticallyCentered, showCloseButton, size, title, handleClose } = options, dialogProps = __rest(options, ["isVerticallyCenter", "isVerticallyCentered", "showCloseButton", "size", "title", "handleClose"]);
    dialog.id = `vega-dialog-${generateUUID()}`;
    dialog.dialogTitle = title;
    dialog.modalProps = { isVerticallyCenter, isVerticallyCentered, showCloseButton, size, handleClose };
    Object.keys(dialogProps).forEach((propName) => {
      if (dialogProps[propName] !== undefined) {
        dialog[propName] = dialogProps[propName];
      }
    });
    // eslint-disable-next-line no-restricted-globals
    document.body.append(dialog);
    return dialog;
  }
}
__decorate([
  InjectVegaTelemetrySlimmer()
], VegaDialogController.prototype, "vegaPublicAPIRuntimeMetricsSlimmer", void 0);
export const VegaDialog = new VegaDialogController();
