"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.usePortalProvider = usePortalProvider;
var _react = require("react");
var _common = require("./common");
var _createPortalRendererComponent = require("./createPortalRendererComponent");
var _PortalManager = require("./PortalManager");
/**
 * Initializes PortalManager and creates PortalRendererComponent. Offers an API (portalProviderAPI) for managing portals.
 * @returns {[PortalProviderAPI, PortalRendererComponent]} An array containing two elements:
 *         1. portalProviderAPI: An object providing an API for rendering and removing portals.
 *         2. PortalRenderer: A React component responsible for rendering the portal content.
 */
function usePortalProvider() {
  var portalManager = (0, _react.useMemo)(function () {
    return new _PortalManager.PortalManager();
  }, []);
  var PortalRenderer = (0, _react.useMemo)(function () {
    return (0, _createPortalRendererComponent.createPortalRendererComponent)(portalManager);
  }, [portalManager]);
  var portalProviderAPI = (0, _react.useMemo)(function () {
    return (0, _common.getPortalProviderAPI)(portalManager);
  }, [portalManager]);

  // Cleanup on unmount
  (0, _react.useEffect)(function () {
    return function () {
      portalProviderAPI.destroy();
    };
  }, [portalManager, portalProviderAPI]);
  return [portalProviderAPI, PortalRenderer];
}