import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
import * as React from 'react';
import { mergeHandlers } from '../../utils/mergeHandlers.js';
import { mergeRefs } from '../../utils/setRefList.js';

var _excluded = ["children"];
var Slot = /*#__PURE__*/React.forwardRef(function (props, forwardedRef) {
  var children = props.children,
    slotProps = _objectWithoutProperties(props, _excluded);
  if (! /*#__PURE__*/React.isValidElement(children)) {
    return null;
  }
  var child = children;
  var childProps = child.props;
  var mergedProps = _objectSpread2({}, slotProps);

  // merge event handlers
  for (var 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 = _objectSpread2(_objectSpread2({}, slotProps.style), childProps.style);
  }
  mergedProps.ref = mergeRefs(childProps.ref, forwardedRef);
  return /*#__PURE__*/React.cloneElement(children, mergedProps);
});

export { Slot };
