import React__default, { forwardRef, useContext, useState, useImperativeHandle } from "react";
import { ConfigContext } from "../ConfigProvider/index.js";
import { jsx, Fragment } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
  if (pack || arguments.length === 2)
    for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
        if (!ar)
          ar = Array.prototype.slice.call(from, 0, i);
        ar[i] = from[i];
      }
    }
  return to.concat(ar || Array.prototype.slice.call(from));
};
var ContextHolderElement = forwardRef(function(_props, ref) {
  var configContext = useContext(ConfigContext);
  var _a = __read(useState([]), 2), instances = _a[0], setInstances = _a[1];
  function addInstance(ins) {
    setInstances(function(originInstances) {
      return __spreadArray(__spreadArray([], __read(originInstances), false), [ins], false);
    });
  }
  function removeInstance(ins) {
    setInstances(function(originInstances) {
      return originInstances.filter(function(originIns) {
        return ins !== originIns;
      });
    });
  }
  function getContextConfig() {
    return configContext;
  }
  useImperativeHandle(ref, function() {
    return {
      addInstance,
      removeInstance,
      getContextConfig
    };
  });
  return /* @__PURE__ */ jsx(Fragment, {
    children: React__default.Children.map(instances, function(child, index) {
      return React__default.cloneElement(child, {
        key: index
      });
    })
  });
});
const ContextHolderElement$1 = ContextHolderElement;
export {
  ContextHolderElement$1 as default
};
//# sourceMappingURL=contextHolder.js.map
