import * as React from "react";
import { mergeRefs, mergeHandlers } from "../../utils";
export const Slot = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
    const { children, ...slotProps } = props;
    if (!/*#__PURE__*/ React.isValidElement(children)) {
        return null;
    }
    const child = children;
    const childProps = child.props;
    const mergedProps = {
        ...slotProps
    };
    // merge event handlers
    for(const key in slotProps){
        if (/^on[A-Z]/.test(key)) {
            mergedProps[key] = mergeHandlers(childProps[key], slotProps[key]);
        }
    }
    if (childProps.className || slotProps.className) {
        mergedProps.className = [
            slotProps.className,
            childProps.className
        ].filter(Boolean).join(' ');
    }
    // merge style
    if (childProps.style || slotProps.style) {
        mergedProps.style = {
            ...slotProps.style,
            ...childProps.style
        };
    }
    mergedProps.ref = mergeRefs(childProps.ref, forwardedRef);
    return /*#__PURE__*/ React.cloneElement(children, mergedProps);
});
