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

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

const defaultProps = {
  children: '',
  className: '',
  defaultClassName: 'sui-a-label-value',
  isLabelUppercase: false,
  label: '',
  size: '',
  tag: 'div',
};
export const LabelValue = ({
  children,
  className,
  defaultClassName,
  isLabelUppercase,
  label,
  size,
  tag: Tag,
  ...attributes
}) => {
  const classes = classnames(
    className,
    defaultClassName,
    isLabelUppercase ? 'as--label-uppercase' : '',
    modifierCSS(size)
  );

  return (
    <Tag {...attributes} className={classes}>
      <div className="sui-a-label-value__label">
        {label}
      </div>
      <div className="sui-a-label-value__value">
        {children}
      </div>
    </Tag>
  );
};

LabelValue.propTypes = propTypes;
LabelValue.defaultProps = defaultProps;
