/**
 * Internal dependencies.
 */
import DynamicImageButton from '@spectra-pro-extensions/dynamic-content/components/DynamicImageButton';

/**
 * Higher Order Component to enhance core/image with dynamic content capability
 *
 * @since x.x.x
 *
 * @param {Function} BlockEdit - Original BlockEdit component
 * @return {Function} Enhanced component
 */
const withCoreDynamicImage = ( BlockEdit ) => ( props ) => {
	const { name } = props;

	// Early return if not allowed block.
	if ( 'core/image' !== name ) {
		return <BlockEdit { ...props } />;
	}

	const { name: blockName, attributes, setAttributes } = props;

	return (
		<>
			<BlockEdit { ...props } />
			<DynamicImageButton
				blockName={ blockName }
				attributes={ attributes }
				setAttributes={ setAttributes }
			/>
		</>
	);
};

export default withCoreDynamicImage;
