var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { tagPropType, mapToCssModules } from './Shared/helper.js';

//component - CoreUI / CModalHeader

var CModalHeader = function CModalHeader(props) {
  var Tag = props.tag,
      children = props.children,
      className = props.className,
      cssModule = props.cssModule,
      innerRef = props.innerRef,
      toggle = props.toggle,
      WrapTag = props.wrapTag,
      closeAriaLabel = props.closeAriaLabel,
      charCode = props.charCode,
      close = props.close,
      mainClassName = props.mainClassName,
      mainProps = props.mainProps,
      attributes = _objectWithoutProperties(props, ['tag', 'children', 'className', 'cssModule', 'innerRef', 'toggle', 'wrapTag', 'closeAriaLabel', 'charCode', 'close', 'mainClassName', 'mainProps']);

  //render

  var closeButton = void 0;

  var classes = mapToCssModules(classNames(className, 'modal-header'), cssModule);

  var mainClasses = mapToCssModules(classNames(mainClassName, 'modal-title'), cssModule);

  if (!close && toggle) {
    var closeIcon = typeof charCode === 'number' ? String.fromCharCode(charCode) : charCode;
    closeButton = React.createElement(
      'button',
      { type: 'button', onClick: toggle, className: mapToCssModules('close', cssModule), 'aria-label': closeAriaLabel },
      React.createElement(
        'span',
        { 'aria-hidden': 'true' },
        closeIcon
      )
    );
  }

  return React.createElement(
    WrapTag,
    _extends({}, attributes, { className: classes, ref: innerRef }),
    React.createElement(
      Tag,
      _extends({ className: mainClasses }, mainProps),
      children
    ),
    close || closeButton
  );
};

CModalHeader.propTypes = process.env.NODE_ENV !== "production" ? {
  tag: tagPropType,
  children: PropTypes.node,
  className: PropTypes.string,
  cssModule: PropTypes.object,
  //
  innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  wrapTag: tagPropType,
  toggle: PropTypes.func,
  closeAriaLabel: PropTypes.string,
  charCode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  close: PropTypes.object,
  mainClassName: PropTypes.string,
  mainProps: PropTypes.object
} : {};

CModalHeader.defaultProps = {
  tag: 'h5',
  wrapTag: 'div',
  closeAriaLabel: 'Close',
  charCode: 215
};

export default CModalHeader;