"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.renderApp = renderApp;
var _react = _interopRequireDefault(require("react"));
var _reactDom = require("react-dom");
var _shared_imports = require("../shared_imports");
var _services = require("../services");
var _tracker = require("../services/tracker");
var localStorageObjectClient = _interopRequireWildcard(require("../lib/local_storage_object_client"));
var _containers = require("./containers");
var _contexts = require("./contexts");
var _lib = require("./lib");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/*
 * 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 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

function renderApp({
  I18nContext,
  notifications,
  docLinkVersion,
  usageCollection,
  element,
  http,
  theme$,
  docLinks,
  autocompleteInfo
}) {
  const trackUiMetric = (0, _tracker.createUsageTracker)(usageCollection);
  trackUiMetric.load('opened_app');
  const storage = (0, _services.createStorage)({
    engine: window.localStorage,
    prefix: 'sense:'
  });
  (0, _services.setStorage)(storage);
  const history = (0, _services.createHistory)({
    storage
  });
  const settings = (0, _services.createSettings)({
    storage
  });
  const objectStorageClient = localStorageObjectClient.create(storage);
  const api = (0, _lib.createApi)({
    http
  });
  const esHostService = (0, _lib.createEsHostService)({
    api
  });
  autocompleteInfo.mapping.setup(http, settings);
  (0, _reactDom.render)( /*#__PURE__*/_react.default.createElement(I18nContext, null, /*#__PURE__*/_react.default.createElement(_shared_imports.KibanaThemeProvider, {
    theme$: theme$
  }, /*#__PURE__*/_react.default.createElement(_contexts.ServicesContextProvider, {
    value: {
      docLinkVersion,
      docLinks,
      services: {
        esHostService,
        storage,
        history,
        settings,
        notifications,
        trackUiMetric,
        objectStorageClient,
        http,
        autocompleteInfo
      },
      theme$
    }
  }, /*#__PURE__*/_react.default.createElement(_contexts.RequestContextProvider, null, /*#__PURE__*/_react.default.createElement(_contexts.EditorContextProvider, {
    settings: settings.toJSON()
  }, /*#__PURE__*/_react.default.createElement(_containers.Main, null)))))), element);
  return () => (0, _reactDom.unmountComponentAtNode)(element);
}