import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React from 'react';
import PropTypes from 'prop-types';
import { createChainedFunction, useClassNames } from '../utils';
import { ModalContext } from './Modal';
import CloseButton from '../CloseButton';
var defaultProps = {
  as: 'div',
  closeButton: true,
  classPrefix: 'modal-header'
};
var ModalHeader = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var Component = props.as,
      classPrefix = props.classPrefix,
      className = props.className,
      closeButton = props.closeButton,
      children = props.children,
      onClose = props.onClose,
      rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "className", "closeButton", "children", "onClose"]);

  var _useClassNames = useClassNames(classPrefix),
      merge = _useClassNames.merge,
      withClassPrefix = _useClassNames.withClassPrefix,
      prefix = _useClassNames.prefix;

  var classes = merge(className, withClassPrefix());
  var buttonElement = /*#__PURE__*/React.createElement(ModalContext.Consumer, null, function (context) {
    return /*#__PURE__*/React.createElement(CloseButton, {
      className: prefix('close'),
      onClick: createChainedFunction(onClose, context === null || context === void 0 ? void 0 : context.onModalClose)
    });
  });
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
    ref: ref,
    className: classes
  }), closeButton && buttonElement, children);
});
ModalHeader.displayName = 'ModalHeader';
ModalHeader.defaultProps = defaultProps;
ModalHeader.propTypes = {
  as: PropTypes.elementType,
  classPrefix: PropTypes.string,
  className: PropTypes.string,
  closeButton: PropTypes.bool,
  children: PropTypes.node,
  onHide: PropTypes.func
};
export default ModalHeader;