function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { useMemo, Children, cloneElement, isValidElement } from "react";
import setRef from "../../../mixins/set-ref";
var getChild = function getChild(children) {
  if (Children.count(children) !== 1) return Children.only(children);
  if (/*#__PURE__*/isValidElement(children)) return children;
  return /*#__PURE__*/React.createElement("span", null, children);
};
export default (function (children, _ref, childProps) {
  return useMemo(function () {
    if (children === undefined || children === null) return children;
    if (typeof children === "function") {
      return children(_extends({
        ref: function ref(node) {
          return setRef(_ref, node);
        }
      }, childProps));
    }
    var child = getChild(children);
    return /*#__PURE__*/cloneElement(child, _extends({}, childProps, {
      ref: function ref(node) {
        setRef(_ref, node);
        setRef(child.props.ref, node);
      }
    }));
  }, [children, childProps.open]);
});