import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const propTypes = {
  /**
   * The component used for the root node.
   * Either a string to use a DOM element or a component.
   */
  tag: PropTypes.elementType,
  defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
  className: PropTypes.string,
  pretitle: PropTypes.node,
  subtitle: PropTypes.node,
  title: PropTypes.node.isRequired,
};

const defaultProps = {
  tag: 'div',
  defaultClassName: 'sui-o-secondary-nav__header',
  className: '',
  pretitle: '',
  subtitle: '',
};

export const SecondaryNavHeader = (props) => {
  const {
    tag: Tag,
    defaultClassName,
    className,
    pretitle,
    subtitle,
    title,
    ...attributes
  } = props;

  const classes = classnames(
    defaultClassName,
    className
  );

  return (
    <Tag className={classes} {...attributes}>
      {!!pretitle && (
        <div className="sui-o-secondary-nav__pretitle">
          {pretitle}
        </div>
      )}
      <div className="sui-o-secondary-nav__title">
        {title}
      </div>
      {!!subtitle && (
        <div className="sui-o-secondary-nav__subtitle">
          {subtitle}
        </div>
      )}
    </Tag>
  );
};

SecondaryNavHeader.propTypes = propTypes;
SecondaryNavHeader.defaultProps = defaultProps;
