<?php
/**
 * Block patterns
 *
 * @package car-dealership-carkit
 * @since 1.0.0
 */

/**
 * This is an example of how to unregister a core block pattern and a block pattern category.
 * Must be called after the patterns and pattern categories that you want to unregister have been added.
 *
 * @see https://developer.wordpress.org/reference/functions/unregister_block_pattern/
 * @see https://developer.wordpress.org/reference/functions/unregister_block_pattern_category/
 *
 * @since 1.0.0
 *
 * @return void
 */
function car_dealership_carkit_block_woo_unregister_patterns() {
	unregister_block_pattern( 'core/query-small-posts' );
	unregister_block_pattern( 'core/query-large-title-posts' );
	unregister_block_pattern( 'core/query-offset-posts' );
	unregister_block_pattern_category( 'featured' );
}
add_action( 'init', 'car_dealership_carkit_block_woo_unregister_patterns', 10 );

/**
 * Skeleton FSE : Block Patterns
 *
 * @since Skeleton FSE 1.0
 */

function car_dealership_carkit_register_block_patterns() {
	$block_pattern_categories = array(
		'car-dealership-carkit' => array( 'label' => esc_html__( 'Car Dealership CarKit', 'car-dealership-carkit' ) ),
	);

	/**
	 * Filters the theme block pattern categories.
	 *
	 * @since Skeleton FSE 1.0
	 *
	 */
	$block_pattern_categories = apply_filters( 'car-dealership-carkit', $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 ); // phpcs:ignore WPThemeReview.PluginTerritory.ForbiddenFunctions.editor_blocks_register_block_pattern_category
		}
	}

	$block_patterns = array(
		'brands-row',	
		'car-rental-services',
		'car-footer',
		'car-header',
	);

	/**
	 * Filters the theme block patterns.
	 *
	 * @since Skeleton FSE 1.0
	 * 
	 * @param array $block_patterns List of block patterns by name.
	 *
	 */
	$block_patterns = apply_filters( 'car_dealership_carkit_block_patterns', $block_patterns );

	foreach ( $block_patterns as $block_pattern ) {
		$pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );

		register_block_pattern( // phpcs:ignore WPThemeReview.PluginTerritory.ForbiddenFunctions.editor_blocks_register_block_pattern
			'car-dealership-carkit/' . $block_pattern,
			require $pattern_file // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
		);
	}
}
add_action( 'init', 'car_dealership_carkit_register_block_patterns', 9 );

