<?php
/**
 * Red icons for the custom Brentwood blocks in the editor.
 *
 * The site has ~25 bespoke blocks under the `bw/*` and `brentwood/*` namespaces.
 * To help the client tell them apart from core / Kadence blocks, we tint their
 * editor icons brand-red (#c8272c). Rather than edit every block.json, the colour
 * is applied centrally:
 *   - assets/bw-block-icons.js  — a blocks.registerBlockType filter that sets each
 *     Brentwood block's icon `foreground` colour (colours it in the inserter, the
 *     list view and the block toolbar).
 *   - assets/bw-block-icons.css — a scoped guarantee for the inserter list.
 *
 * Editor-only: block icons never render on the front end, so nothing loads there.
 *
 * @package Kadence-Child
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Load the icon-colouring script + stylesheet into the block editor. Priority 1
 * (and the wp-blocks/wp-hooks deps) so the registerBlockType filter is registered
 * before the blocks register — mirrors bw-redborder-editor.js.
 */
add_action(
	'enqueue_block_editor_assets',
	function () {
		$theme = get_stylesheet_directory();
		$uri   = get_stylesheet_directory_uri();

		$js = $theme . '/assets/bw-block-icons.js';
		if ( file_exists( $js ) ) {
			wp_enqueue_script(
				'bw-block-icons',
				$uri . '/assets/bw-block-icons.js',
				array( 'wp-blocks', 'wp-hooks' ),
				filemtime( $js ),
				true
			);
		}

		$css = $theme . '/assets/bw-block-icons.css';
		if ( file_exists( $css ) ) {
			wp_enqueue_style(
				'bw-block-icons',
				$uri . '/assets/bw-block-icons.css',
				array(),
				filemtime( $css )
			);
		}
	},
	1
);
