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

const propTypes = {
  /**
   * The content of the add placeholder.
   */
  children: PropTypes.node,

  /**
   * The class to add to the root component.
   */
  className: PropTypes.string,

  /**
   * The Add Placeholder size.
   */
  size: PropTypes.oneOf(['', 'sm', 'lg']),

  /**
   * Disable the add placeholder.
   */
  isDisabled: PropTypes.bool,

  /**
   * 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: '',
  size: '',
  isDisabled: false,
  tag: 'div',
};

export const AddPlaceholder = forwardRef(({
  children,
  className,
  isDisabled,
  tag: Tag,
  size,
  ...props
}, ref) => {
  const classes = classnames(
    modifierCSS(size),
    {
      'as--disabled': isDisabled,
    },
    className,
  );

  return (
    <Tag
      className={`sui-a-add-placeholder ${classes}`}
      ref={ref}
      {...props}
    >
      {children}
    </Tag>
  );
});

AddPlaceholder.propTypes = propTypes;
AddPlaceholder.defaultProps = defaultProps;
