/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../_virtual/_rolldown/runtime.cjs");
const require_utils_composeRefs = require("./composeRefs.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/utils/createSlot.tsx
/**
* Essentially @radix-ui/react-slot typed as a generic we can use with asChild
* @link: https://www.radix-ui.com/primitives/docs/utilities/slot
**/
function createSlot() {
	const Slot = (0, react.forwardRef)((props, forwardedRef) => {
		const { children, ...slotProps } = props;
		const childrenArray = react.Children.toArray(children);
		const slottable = childrenArray.find(isSlottable);
		if (slottable) {
			const newElement = slottable.props.children;
			const newChildren = childrenArray.map((child) => {
				if (child === slottable) {
					if (react.Children.count(newElement) > 1) return react.Children.only(null);
					return (0, react.isValidElement)(newElement) ? newElement.props.children : null;
				} else return child;
			});
			return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotClone, {
				...slotProps,
				ref: forwardedRef,
				children: (0, react.isValidElement)(newElement) ? (0, react.cloneElement)(newElement, void 0, newChildren) : null
			});
		}
		return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotClone, {
			...slotProps,
			ref: forwardedRef,
			children
		});
	});
	Slot.displayName = "Slot";
	const SlotClone = (0, react.forwardRef)((props, forwardedRef) => {
		const { children, ...slotProps } = props;
		if ((0, react.isValidElement)(children)) {
			const childProps = children.props;
			return (0, react.cloneElement)(children, {
				...mergeProps(slotProps, childProps),
				ref: forwardedRef ? require_utils_composeRefs.composeRefs(forwardedRef, children.props.ref ?? children.ref) : children.props.ref ?? children.ref
			});
		}
		return react.Children.count(children) > 1 ? react.Children.only(null) : null;
	});
	SlotClone.displayName = "SlotClone";
	const Slottable = ({ children }) => {
		return children;
	};
	function isSlottable(child) {
		return (0, react.isValidElement)(child) && child.type === Slottable;
	}
	function mergeProps(slotProps, childProps) {
		const overrideProps = { ...childProps };
		for (const propName in childProps) {
			const slotPropValue = slotProps[propName];
			const childPropValue = childProps[propName];
			if (/^on[A-Z]/.test(propName)) {
				if (slotPropValue && childPropValue) overrideProps[propName] = (...args) => {
					childPropValue(...args);
					slotPropValue(...args);
				};
				else if (slotPropValue) overrideProps[propName] = slotPropValue;
			} else if (propName === "style") overrideProps[propName] = {
				...slotPropValue,
				...childPropValue
			};
		}
		return {
			...slotProps,
			...overrideProps
		};
	}
	return Slot;
}
//#endregion
exports.createSlot = createSlot;
