<?php
/**
 * Register custom Gutenberg blocks.
 *
 * All blocks use server-side rendering (PHP) with no build step.
 * The editor uses ServerSideRender for preview.
 *
 * Blocks:
 *   - northfield/hero-gallery: Full-width hero with optional image rotation
 *   - northfield/event-grid: Grid of events with filtering options
 *   - northfield/alert-banner: Dismissible alert banner
 *
 * @package Northfield_Theatre
 * @since 1.0.0
 */

function northfield_register_blocks() {
	$blocks_dir = NORTHFIELD_DIR . '/blocks';

	$blocks = array(
		'hero-gallery',
		'event-grid',
		'alert-banner',
	);

	foreach ( $blocks as $block ) {
		$block_dir = $blocks_dir . '/' . $block;
		if ( file_exists( $block_dir . '/block.json' ) ) {
			register_block_type( $block_dir );
		}
	}
}
add_action( 'init', 'northfield_register_blocks' );

/**
 * Enqueue block editor assets.
 */
function northfield_block_editor_assets() {
	wp_enqueue_script(
		'northfield-blocks-editor',
		NORTHFIELD_URI . '/assets/js/blocks-editor.js',
		array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-server-side-render', 'wp-data' ),
		NORTHFIELD_VERSION,
		true
	);
}
add_action( 'enqueue_block_editor_assets', 'northfield_block_editor_assets' );
