"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _utils = require("../utils");

var _Modal = require("./Modal");

var _CloseButton = _interopRequireDefault(require("../CloseButton"));

var defaultProps = {
  as: 'div',
  closeButton: true,
  classPrefix: 'modal-header'
};

var ModalHeader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var Component = props.as,
      classPrefix = props.classPrefix,
      className = props.className,
      closeButton = props.closeButton,
      children = props.children,
      onClose = props.onClose,
      rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "closeButton", "children", "onClose"]);

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

  var classes = merge(className, withClassPrefix());

  var buttonElement = /*#__PURE__*/_react.default.createElement(_Modal.ModalContext.Consumer, null, function (context) {
    return /*#__PURE__*/_react.default.createElement(_CloseButton.default, {
      className: prefix('close'),
      onClick: (0, _utils.createChainedFunction)(onClose, context === null || context === void 0 ? void 0 : context.onModalClose)
    });
  });

  return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, rest, {
    ref: ref,
    className: classes
  }), closeButton && buttonElement, children);
});

ModalHeader.displayName = 'ModalHeader';
ModalHeader.defaultProps = defaultProps;
ModalHeader.propTypes = {
  as: _propTypes.default.elementType,
  classPrefix: _propTypes.default.string,
  className: _propTypes.default.string,
  closeButton: _propTypes.default.bool,
  children: _propTypes.default.node,
  onHide: _propTypes.default.func
};
var _default = ModalHeader;
exports.default = _default;