/**
 * 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/textColorHover': parentTextColorHover,
		'spectra-pro/form/checkboxBackgroundColor': parentCheckboxBgColor,
	} = context;

	const {
		textColorHover,
		checkboxBackgroundColor,
		checkboxCheckmarkColor,
	} = attributes;

	return (
		<InspectorColor
			settings={ [
				{
					colorValue: textColorHover || parentTextColorHover,
					label: __( 'Text Hover', 'spectra-pro' ),
					onColorChange: ( value ) => setAttributes( { textColorHover: value } ),
					resetAllFilter: () => setAttributes( { textColorHover: undefined } ),
				},
				{
					colorValue: checkboxBackgroundColor || parentCheckboxBgColor,
					label: __( 'Checkbox Background', 'spectra-pro' ),
					onColorChange: ( value ) => setAttributes( { checkboxBackgroundColor: value } ),
					resetAllFilter: () => setAttributes( { checkboxBackgroundColor: undefined } ),
				},
				{
					colorValue: checkboxCheckmarkColor,
					label: __( 'Checkmark Color', 'spectra-pro' ),
					onColorChange: ( value ) => setAttributes( { checkboxCheckmarkColor: value } ),
					resetAllFilter: () => setAttributes( { checkboxCheckmarkColor: 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 );