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

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

const defaultProps = {
  tag: 'div',
  className: '',
  defaultClassName: 'sui-m-breadcrumb__item',
  isHidden: false,
};

export const BreadcrumbItemContainer = ({
  tag: Tag,
  children,
  defaultClassName,
  className,
  isHidden,
  ...attributes
}) => {
  const classes = classnames(
    defaultClassName,
    className,
    isHidden ? 'as--hidden' : '',
  );

  return (
    <Tag className={classes} {...attributes}>
      {children}
    </Tag>
  );
};

BreadcrumbItemContainer.propTypes = propTypes;
BreadcrumbItemContainer.defaultProps = defaultProps;
