const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_useContainerContext = require("../hooks/useContainerContext.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/pisellDataSourceContainer/utils/withContainer.tsx
const _excluded = ["refId"];
/**
* 支持自定义 ID 的组件 Props
*/
function withContainer(WrappedComponent, displayName) {
	return (0, react.forwardRef)((props, forwardedRef) => {
		const { refId } = props, otherProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
		const containerContext = require_useContainerContext.default(displayName);
		const innerRef = (0, react.useRef)(null);
		(0, react.useImperativeHandle)(forwardedRef, () => {
			return innerRef.current;
		}, []);
		(0, react.useEffect)(() => {
			if (refId && innerRef.current) containerContext.refManager.registerRef(refId, innerRef.current);
			return () => {
				if (refId) containerContext.refManager.unregisterRef(refId);
			};
		}, [refId, containerContext.refManager]);
		const mergedProps = (0, react.useMemo)(() => {
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, containerContext), otherProps);
		}, [otherProps, containerContext]);
		return /* @__PURE__ */ react.default.createElement(WrappedComponent, require_objectSpread2._objectSpread2({ ref: innerRef }, mergedProps));
	});
}
//#endregion
exports.default = withContainer;
