/**
 * 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');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);

//#region src/global/js/utils/Wrap.tsx
/**
* Copyright IBM Corp. 2021, 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 isEmpty = (children) => {
	let result = true;
	react.default.Children.forEach(children, (child) => {
		if (child) result &&= child?.type?.displayName === "Wrap" && isEmpty(child?.props?.children);
	});
	return result;
};
/**
* A simple conditional wrapper that encloses its children in a <div> (or other
* element if specified), passing any supplied attributes to the <div> (or other
* element). The component renders nothing at all if there are no children or
* the children are empty/falsy, or if all the non-falsy children are themselves
* Wrap components that do not wish to render. This behavior can be overridden
* by setting neverRender or alwaysRender to true. Note that if a ref is passed,
* the ref.current will be set to the wrapper element if it renders, and will
* remain undefined if it does not render.
*/
const Wrap = react.default.forwardRef(({ alwaysRender, children, element: Wrapper = "div", neverRender, className, title, ...rest }, ref) => (neverRender || isEmpty(children)) && !alwaysRender ? null : /* @__PURE__ */ react.default.createElement(Wrapper, {
	className,
	...rest,
	ref,
	title
}, children));
Wrap.displayName = "Wrap";
Wrap.propTypes = {
	alwaysRender: prop_types.default.bool,
	children: prop_types.default.node,
	className: prop_types.default.string,
	element: prop_types.default.elementType,
	neverRender: prop_types.default.bool,
	title: prop_types.default.string
};

//#endregion
exports.Wrap = Wrap;