import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useLayoutEffect, useMemo, useState } from 'react';
import { PortalBucket } from './PortalBucket';
export function createPortalRendererComponent(portalManager) {
  return function PortalRenderer() {
    var _useState = useState(portalManager.getBuckets()),
      _useState2 = _slicedToArray(_useState, 2),
      buckets = _useState2[0],
      setBuckets = _useState2[1];
    useLayoutEffect(function () {
      portalManager.registerPortalRenderer(setBuckets);
      return function () {
        portalManager.unregisterPortalRenderer();
      };
    }, []);
    var portalsElements = useMemo(
    // Ignored via go/ees005
    // eslint-disable-next-line react/no-array-index-key
    function () {
      return buckets.map(function (_, i) {
        return /*#__PURE__*/React.createElement(PortalBucket, {
          key: i,
          id: i,
          portalManager: portalManager
        });
      });
    }, [buckets]);
    return /*#__PURE__*/React.createElement(React.Fragment, null, portalsElements);
  };
}