/**
 * Spectra Pro Responsive Controls Extension
 *
 * This module extends the responsive controls functionality from Spectra free
 * to support Spectra Pro blocks with their specific responsive attributes.
 *
 * @since x.x.x
 */

/**
 * WordPress dependencies
 */
import { addFilter } from '@wordpress/hooks';

/**
 * Block-specific responsive keys for Spectra Pro blocks.
 *
 * Maps each Pro block to an array of attributes that should have responsive behavior.
 * These attributes will be tracked and managed separately for each device view.
 *
 * @since x.x.x
 * @type {Object<string, Array<string>>}
 */
const SPECTRA_PRO_BLOCK_RESPONSIVE_KEYS = {
	'spectra-pro/loop-builder-child-pagination-next-button': [ 'size', 'gap' ],
	'spectra-pro/loop-builder-child-pagination-previous-button': [ 'size', 'gap' ],
	'spectra-pro/loop-builder-child-pagination-page-numbers-button': [ 'size', 'gap' ],
	'spectra-pro/loop-builder-child-filter-checkbox': [ 'checkboxSize', 'itemsGap', 'labelCheckboxGap' ],
	'spectra-pro/loop-builder-child-filter-select': [ 'itemsGap' ],
	'spectra-pro/loop-builder-child-filter-button': [ 'gap' ],
	'spectra-pro/loop-builder-child-search': [ 'gap' ],
	'spectra-pro/loop-builder-child-sort': [ 'itemsGap' ],
	'spectra-pro/loop-builder-child-reset-all-button': [ 'size', 'gap' ],
	'spectra-pro/form-icon': [ 'size' ],
	'spectra-pro/form-button': [ 'size', 'gap', 'width' ],
	'spectra-pro/form-input-wrapper': [ 'gap' ],
	'spectra-pro/form-field-wrapper': [ 'gap' ],
	'spectra-pro/login': [ 'width' ],
	'spectra-pro/register': [ 'width' ],
};

/**
 * Add Spectra Pro block-specific responsive keys.
 *
 * This filter extends the responsive controls from the free plugin
 * to support Pro block-specific attributes.
 *
 * @since x.x.x
 * @param {Array}  blockSpecificKeys Existing block-specific keys.
 * @param {string} blockName         The block name.
 * @return {Array} Modified block-specific keys.
 */
addFilter(
	'spectra.responsive-controls.block-responsive-keys',
	'spectra-pro/responsive-controls/block-keys',
	( blockSpecificKeys, blockName ) => {
		// If it's a Pro block, add its specific responsive keys
		if ( SPECTRA_PRO_BLOCK_RESPONSIVE_KEYS[ blockName ] ) {
			return [ ...blockSpecificKeys, ...SPECTRA_PRO_BLOCK_RESPONSIVE_KEYS[ blockName ] ];
		}

		return blockSpecificKeys;
	}
);
