import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const propTypes = {
  /**
   * The Paper content.
   */
  children: PropTypes.node,

  /**
   * The className property allows you to add more classes to the component.
   */
  className: PropTypes.string,

  /**
   * The component default class.
   */
  defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),

  /**
   * The Paper elevation. Accept string or number.
   */
  elevation: PropTypes.oneOf([
    100, 200, 300, 400, 500, 600,
    '100', '200', '300', '400', '500', '600',
  ]),

  /**
   * 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-paper',
  elevation: 100,
  tag: 'div',
};

export const Paper = forwardRef(({
  children,
  className,
  defaultClassName,
  elevation,
  tag: Tag,
  ...props
}, ref) => {
  const classes = classnames(
    defaultClassName,
    elevation ? `as--elevation-${elevation}` : '',
    className,
  );

  return (
    <Tag className={classes} ref={ref} data-testid={`paper-elevation-${elevation}`} {...props}>
      {children}
    </Tag>
  );
});

Paper.propTypes = propTypes;
Paper.defaultProps = defaultProps;
