import PropTypes from 'prop-types';
import { widont } from 'journalize';
import MarkdownContent from "../../content/MarkdownContent/index.js";
import classes from './styles.module.scss';

/**
 * The headline of a module.
 */
const ModuleHeadline = function ModuleHeadline(props) {
  const {
    children,
    as: Tag
  } = props;
  const child = typeof children !== 'string' ? children : <MarkdownContent source={widont(children)} inline unstyled />;
  return <Tag className={classes.headline}>
      {child}
    </Tag>;
};
ModuleHeadline.defaultProps = {
  children: undefined,
  as: 'h2'
};
ModuleHeadline.propTypes = {
  /**
   * The contents of the headline.
   */
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
  /**
   * The tag to render as the headline.
   */
  as: PropTypes.elementType
};
export default ModuleHeadline;