import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { modifierCSS } from '../../../helpers';

const propTypes = {
  className: PropTypes.string,
  color: PropTypes.oneOf(['', 'primary', 'success', 'warning', 'danger']),
  defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
  max: PropTypes.string,
  size: PropTypes.oneOf(['', 'xs', 'sm', 'lg']),
  role: PropTypes.string,
  /**
   * The component used for the root node.
   * Either a string to use a DOM element or a component.
   */
  tag: PropTypes.elementType,
  value: PropTypes.string,

};

const defaultProps = {
  className: '',
  color: '',
  defaultClassName: 'sui-a-progress-bar',
  max: '100',
  size: '',
  role: 'progressbar',
  tag: 'progress',
  value: '0',
};

export const ProgressBar = ({
  className,
  color,
  defaultClassName,
  max,
  size,
  role,
  tag: Tag,
  value,
  ...attributes
}) => {
  const classes = classnames(
    className,
    defaultClassName,
    modifierCSS(color),
    modifierCSS(size)
  );

  return (
    <Tag className={classes} {...attributes} role={role} value={value} max={max} />
  );
};

ProgressBar.propTypes = propTypes;
ProgressBar.defaultProps = defaultProps;
