import { React, PropTypes, classnames } from '@gravityforms/libraries';
import { spacerClasses } from '@gravityforms/utils';

const { forwardRef } = React;

/**
 * @module DotIndicator
 * @description An icon indicator component.
 *
 * @since 2.3.1
 *
 * @param {object}                     props                  Component props.
 * @param {string}                     props.bgColor          Background color for the indicator.
 * @param {JSX.Element}                props.children         React element children.
 * @param {object}                     props.customAttributes Custom attributes for the component.
 * @param {string|Array|object}        props.customClasses    Custom classes for the component.
 * @param {string}                     props.icon             The icon of the indicator if the type is `unstyled`.
 * @param {string}                     props.iconColor        The color of the icon if the type is `unstyled`.
 * @param {string}                     props.iconPrefix       The prefix for the icon library to be used.
 * @param {string|number|Array|object} props.spacing          The spacing for the component, as a string, number, array, or object.
 * @param {string}                     props.type             The type of the indicator, one of `info`, `warning`, `success`, or `error`.
 * @param {object|null}                ref                    Ref to the component.
 *
 * @return {JSX.Element} The icon indicator component.
 *
 * @example
 * import DotIndicator from '@gravityforms/components/react/admin/modules/Indicators/DotIndicator';
 *
 * return (
 *     <DotIndicator type="info">
 *         { children }
 *     </DotIndicator>
 * );
 *
 */
const DotIndicator = forwardRef( ( {
	children = null,
	customAttributes = {},
	customClasses = {},
	spacing = '',
	type = 'success',
}, ref ) => {
	const componentProps = {
		className: classnames( {
			'gform-indicator': true,
			'gform-indicator--dot': true,
			[ `gform-indicator--${ type }` ]: true,
			...spacerClasses( spacing ),
		}, customClasses ),
		...customAttributes,
	};

	return (
		<span { ...componentProps } ref={ ref }>
			{ children }
		</span>
	);
} );

DotIndicator.propTypes = {
	children: PropTypes.oneOfType( [
		PropTypes.arrayOf( PropTypes.node ),
		PropTypes.node,
	] ),
	customAttributes: PropTypes.object,
	customClasses: PropTypes.oneOfType( [
		PropTypes.string,
		PropTypes.array,
		PropTypes.object,
	] ),
	spacing: PropTypes.oneOfType( [
		PropTypes.string,
		PropTypes.number,
		PropTypes.array,
		PropTypes.object,
	] ),
	type: PropTypes.string,
};

DotIndicator.displayName = 'Indicators/DotIndicator';

export default DotIndicator;
