<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package   Matchday
 * @since     1.0.0
 * @version   1.0.1
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function matchday_body_classes($classes) {
	// Adds base styles
	$classes[] = 'antialiased h-full overflow-x-hidden';

	return $classes;
}
add_filter('body_class', 'matchday_body_classes');

/**
 * Registers block patterns and categories.
 *
 * @since Matchday 1.0.0
 *
 * @return void
 */
function matchday_register_block_pattern_categories() {
	$block_pattern_categories = [
		'matchday-page' => [
			'label' => __('Matchday - Pages', 'matchday'),
		],
		'matchday-sections' => [
			'label' => __('Matchday - Sections', 'matchday'),
		],
		'matchday-cards' => [
			'label' => __('Matchday - Cards', 'matchday'),
		],
		'matchday-lists' => [
			'label' => __('Matchday - Lists', 'matchday'),
		],
		'matchday-posts' => [
			'label' => __('Matchday - Posts', 'matchday'),
		],
		'matchday-cta' => [
			'label' => __('Matchday - Call to Action', 'matchday'),
		],
		'matchday-components' => [
			'label' => __('Matchday - Components', 'matchday'),
		],
	];

	/**
	 * Filters the theme block pattern categories.
	 *
	 * @since Matchday 1.0.0
	 *
	 * @param array[] $block_pattern_categories {
	 *     An associative array of block pattern categories, keyed by category name.
	 *
	 *     @type array[] $properties {
	 *         An array of block category properties.
	 *
	 *         @type string $label A human-readable label for the pattern category.
	 *     }
	 * }
	 */
	$block_pattern_categories = apply_filters(
		'matchday_block_pattern_categories',
		$block_pattern_categories,
	);

	foreach ($block_pattern_categories as $name => $properties) {
		if (
			!WP_Block_Pattern_Categories_Registry::get_instance()->is_registered(
				$name,
			)
		) {
			register_block_pattern_category($name, $properties);
		}
	}
}
add_action('init', 'matchday_register_block_pattern_categories', 9);

/**
 * Register block styles.
 */

if (!function_exists('matchday_block_styles')):
	/**
	 * Register custom block styles
	 *
	 * @since Matchday 1.0.0
	 * @return void
	 */
	function matchday_block_styles() {
		register_block_style('core/heading', [
			'name' => 'matchday-with-line',
			'label' => __('With Line', 'matchday'),
		]);

		register_block_style('core/paragraph', [
			'name' => 'matchday-lead',
			'label' => __('Lead', 'matchday'),
		]);

		register_block_style('core/separator', [
			'name' => 'matchday-vertical',
			'label' => __('Vertical', 'matchday'),
		]);

		register_block_style('core/list', [
			'name' => 'matchday-vertical',
			'label' => __('No Bullets', 'matchday'),
		]);
	}
endif;

add_action('init', 'matchday_block_styles');
