/**
 * External dependencies.
 */
import { memo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
 * Internal dependencies.
 */
import InspectorColor from '@spectra-components/inspector-color';

/**
 * Element Sub-settings: Color settings that integrate with parent form context.
 *
 * @param {Object} props The element props.
 * @since 2.0.0
 * @return {Element} The rendered color settings.
 */
const ColorSettings = memo( ( props ) => {
	const {
		clientId,
		setAttributes,
		attributes,
		context = {}
	} = props;

	// Get context colors from parent login form
	const {
		'spectra-pro/form/linkColorHover': parentLinkColorHover
	} = context;

	const {
		textColorHover
	} = attributes;

	return (
		<InspectorColor
			settings={ [
				{
					colorValue: textColorHover || parentLinkColorHover,
					label: __( 'Text Hover Color', 'spectra-pro' ),
					onColorChange: ( value ) => setAttributes( { textColorHover: value } ),
					resetAllFilter: () => setAttributes( { textColorHover: undefined } ),
				}
			] }
			panelId={ clientId }
		/>
	);
} );

/**
 * The Editor settings for this block.
 *
 * @param {Object} props The element props.
 * @since 2.0.0
 * @return {Element} The rendered settings.
 */
const Settings = ( props ) => {
	return (
		<ColorSettings { ...{ ...props } } />
	);
};

export default memo( Settings );