/**
 * External dependencies.
 */
import { addFilter } from '@wordpress/hooks';
import { registerFormatType } from '@wordpress/rich-text';

/**
 * Internal dependencies.
 */
import DynamicContentFormat from '@spectra-pro-extensions/dynamic-content/formats/DynamicContentFormat';
import withDynamicContent from '@spectra-pro-extensions/dynamic-content/enhancers/withDynamicContent';
import withDynamicImage from '@spectra-pro-extensions/dynamic-content/enhancers/withDynamicImage';
import MediaPickerWithDynamicImage from '@spectra-pro-extensions/dynamic-content/components/MediaPickerWithDynamicImage';
import withDynamicContentAttributes from '@spectra-pro-extensions/dynamic-content/enhancers/withDynamicContentAttributes';
import withCoreDynamicImage from '@spectra-pro-extensions/dynamic-content/enhancers/withCoreDynamicImage';
import LinkControlWithDynamicLink from '@spectra-pro-extensions/dynamic-content/components/LinkControlWithDynamicLink';
/**
 * Registers a custom rich text format type for dynamic content.
 *
 * This format enables dynamic content capabilities in rich text fields.
 *
 * @type {string} 'spectra-pro/dynamic-content' - Unique format identifier.
 * @type {Object} DynamicContentFormat - Format configuration object.
 */
registerFormatType( 'spectra-pro/dynamic-content', DynamicContentFormat );

// Applies Higher-Order Component to BlockEdit for text dynamic tags.
addFilter( 'editor.BlockEdit', 'spectra-pro-v2/dynamic-content', withDynamicContent );

// Applies Higher-Order Component to BlockEdit for image dynamic tags (for Spectra Background Image).
addFilter( 'editor.BlockEdit', 'spectra-pro-v2/dynamic-content/image', withDynamicImage, 9 );

// Extends the media picker with additional controls for the background image.
addFilter(
	'spectra.mediaPicker.extensions',
	'spectra-pro-v2/dynamic-content/extend-media-picker',
	MediaPickerWithDynamicImage
);

//  Enhances the link control UI with additional functionality (dynamic link).
addFilter(
	'spectra.linkControl.Extensions',
	'spectra-pro-v2/dynamic-content/extend-link-control',
	LinkControlWithDynamicLink
);

// Adds dynamic image controls to core/image through a Higher-Order Component.
addFilter( 'editor.BlockEdit', 'spectra/core-image-controls', withCoreDynamicImage, 10 );

// Extends block attributes with dynamic content related properties.
addFilter(
	'blocks.registerBlockType',
	'spectra-pro-v2/dynamic-content/add-dc-image-attributes',
	withDynamicContentAttributes
);
