'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var mergeHandlers = require('../../utils/mergeHandlers.js');
var setRefList = require('../../utils/setRefList.js');

function _interopNamespace(e) {
    if (e && e.__esModule) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n.default = e;
    return n;
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

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

  // merge event handlers
  for (var key in slotProps) {
    if (/^on[A-Z]/.test(key)) {
      mergedProps[key] = mergeHandlers.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 = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, slotProps.style), childProps.style);
  }
  mergedProps.ref = setRefList.mergeRefs(childProps.ref, forwardedRef);
  return /*#__PURE__*/React__namespace.cloneElement(children, mergedProps);
});

exports.Slot = Slot;
