/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
const require_settings = require('../../../settings.js');
const require_index = require('../../../components/FeatureFlags/index.js');
let react = require("react");
let react_dom = require("react-dom");

//#region src/global/js/hooks/usePortalTarget.js
/**
* Copyright IBM Corp. 2023, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const usePortalTarget = (portalTargetIn) => {
	const enablePortalTarget = require_index.useFeatureFlag("default-portal-target-body");
	const [portalTarget, setPortalTarget] = (0, react.useState)(portalTargetIn ?? null);
	(0, react.useEffect)(() => {
		if (portalTargetIn) setPortalTarget(portalTargetIn);
		else if (require_settings.pkg.isFeatureEnabled("default-portal-target-body") || enablePortalTarget) setPortalTarget(document.body);
	}, [portalTargetIn, enablePortalTarget]);
	return (0, react.useCallback)((children) => portalTarget ? (0, react_dom.createPortal)(children, portalTarget) : children, [portalTarget]);
};

//#endregion
exports.usePortalTarget = usePortalTarget;