"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useProfilingPlugin = useProfilingPlugin;
var _common = require("@kbn/observability-plugin/common");
var _use_apm_plugin_context = require("../context/apm_plugin/use_apm_plugin_context");
var _use_fetcher = require("./use_fetcher");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

function useProfilingPlugin() {
  const {
    plugins,
    core
  } = (0, _use_apm_plugin_context.useApmPluginContext)();
  const isProfilingIntegrationEnabled = core.uiSettings.get(_common.apmEnableProfilingIntegration, true);
  const {
    data
  } = (0, _use_fetcher.useFetcher)(callApmApi => {
    return callApmApi('GET /internal/apm/profiling/status');
  }, []);
  const isProfilingAvailable = isProfilingIntegrationEnabled && (data === null || data === void 0 ? void 0 : data.initialized);
  return {
    profilingLocators: isProfilingAvailable ? plugins.observabilityShared.locators.profiling : undefined,
    isProfilingPluginInitialized: data === null || data === void 0 ? void 0 : data.initialized,
    isProfilingIntegrationEnabled,
    isProfilingAvailable
  };
}