'use strict';

require('./global-slimmer-registry-7bbdb1f2.js');
const createPublicApiRuntimeMetricsSlimmer = require('./create-public-api-runtime-metrics-slimmer-1b8ecfb4.js');
require('./dynamic-slimmer-0050c489.js');
require('./misc-3d30df91.js');

const WaitForVegaPayloadDefinition = [
  {
    payloadKey: 'IS_WAITFORVEGA_METHOD_CALLED',
    payloadDescription: 'Indicate if the method waitForVega of public API WaitForVegaHandler 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 === 'WaitForVegaHandler' && methodName === 'handle',
    /**
     * The function checks if the method name is waitForVega.
     *
     * @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;
};
/**
 * WaitForVegaHandler to check whether the vega component has been loaded.
 */
class WaitForVegaHandler {
  constructor() {
    this.vegaPublicAPIRuntimeMetricsSlimmer = createPublicApiRuntimeMetricsSlimmer.createPublicAPIRuntimeMetricsSlimmer(WaitForVegaHandler, ['handle'], WaitForVegaPayloadDefinition);
  }
  /* istanbul ignore next */
  /**
   * Wait for all vega elements to be ready.
   *
   * The below method is e2e-test covered in @see{module:wait-for-vega-should-work-as-expected}
   *
   * @vegaVersion 2.8.0
   */
  async handle() {
    return await Promise.all(
    // eslint-disable-next-line no-restricted-globals
    Array.from(document.querySelectorAll('*:not(.hydrated)'))
      .filter((item) => item.tagName.startsWith('VEGA'))
      .map((item) => { var _a; return (_a = item.componentOnReady) === null || _a === void 0 ? void 0 : _a.call(item); }));
  }
}
__decorate([
  createPublicApiRuntimeMetricsSlimmer.InjectVegaTelemetrySlimmer()
], WaitForVegaHandler.prototype, "vegaPublicAPIRuntimeMetricsSlimmer", void 0);
const WaitForVega = new WaitForVegaHandler();
/* istanbul ignore next */
/**
 * Wait for all vega elements to be ready.
 *
 * The below method is e2e-test covered in @see{module:wait-for-vega-should-work-as-expected}
 *
 * @returns {Promise} A promise that resolves when all vega elements are ready.
 */
const waitForVega = async () => {
  return WaitForVega.handle();
};

exports.waitForVega = waitForVega;
