<?php
/**
 * Vet Care Center: Block Patterns
 *
 * @since Vet Care Center 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function vet_care_center_get_pattern_content( $file_name ) {
	ob_start();
	include get_theme_file_path( '/patterns/' . $file_name . '.php' );
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}

/**
 * Registers block patterns and categories.
 *
 * @since Vet Care Center 1.0
 *
 * @return void
 */
function vet_care_center_register_block_patterns() {

	$patterns = array(
		'header-default' => array(
			'title'      => __( 'Default header', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-headers' ),
			'blockTypes' => array( 'parts/header' ),
		),
		'footer-default' => array(
			'title'      => __( 'Default footer', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-footers' ),
			'blockTypes' => array( 'parts/footer' ),
		),
		'home-banner' => array(
			'title'      => __( 'Home Banner', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-banner' ),
		),
		'product-section' => array(
			'title'      => __( 'Product Sections', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-product-section' ),
		),
		'latest-blog-section' => array(
			'title'      => __( 'Latest Blog Section', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-latest-blog-section' ),
		),
		'primary-sidebar' => array(
			'title'    => __( 'Primary Sidebar', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-sidebars' ),
		),
		'hidden-404' => array(
			'title'    => __( '404 content', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-pages' ),
		),
		'post-listing-single-column' => array(
			'title'    => __( 'Post Single Column', 'vet-care-center' ),
			//'inserter' => false,
			'categories' => array( 'vet-care-center-query' ),
		),
		'post-listing-two-column' => array(
			'title'    => __( 'Post Two Column', 'vet-care-center' ),
			//'inserter' => false,
			'categories' => array( 'vet-care-center-query' ),
		),
		'post-listing-three-column' => array(
			'title'    => __( 'Post Three Column', 'vet-care-center' ),
			//'inserter' => false,
			'categories' => array( 'vet-care-center-query' ),
		),
		'post-listing-four-column' => array(
			'title'    => __( 'Post Four Column', 'vet-care-center' ),
			//'inserter' => false,
			'categories' => array( 'vet-care-center-query' ),
		),
		'feature-post-column' => array(
			'title'    => __( 'Feature Post Column', 'vet-care-center' ),
			//'inserter' => false,
			'categories' => array( 'vet-care-center-query' ),
		),
		'comment-section-1' => array(
			'title'    => __( 'Comment Section 1', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-comment-sections' ),
		),
		'cover-with-post-title' => array(
			'title'    => __( 'Cover With Post Title', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-banner-sections' ),
		),
		'theme-button' => array(
			'title'    => __( 'Theme Button', 'vet-care-center' ),
			'categories' => array( 'vet-care-center-theme-button' ),
		),
	);

	$block_pattern_categories = array(
		'vet-care-center-footers' => array( 'label' => __( 'Footers', 'vet-care-center' ) ),
		'vet-care-center-headers' => array( 'label' => __( 'Headers', 'vet-care-center' ) ),
		'vet-care-center-pages'   => array( 'label' => __( 'Pages', 'vet-care-center' ) ),
		'vet-care-center-query'   => array( 'label' => __( 'Query', 'vet-care-center' ) ),
		'vet-care-center-sidebars'   => array( 'label' => __( 'Sidebars', 'vet-care-center' ) ),
		'vet-care-center-banner'   => array( 'label' => __( 'Banner Sections', 'vet-care-center' ) ),
		'vet-care-center-product-section'   => array( 'label' => __( 'Product Section', 'vet-care-center' ) ),
		'vet-care-center-latest-blog-section'   => array( 'label' => __( 'Latest Blog Section', 'vet-care-center' ) ),
		'vet-care-center-comment-section'   => array( 'label' => __( 'Comment Sections', 'vet-care-center' ) ),
		'vet-care-center-theme-button'   => array( 'label' => __( 'Theme Button Sections', 'vet-care-center' ) ),
	);

	/**
	 * Filters the theme block pattern categories.
	 *
	 * @since Vet Care Center 1.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( 'vet_care_center_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 );
		}
	}

	/**
	 * Filters the theme block patterns.
	 *
	 * @since Vet Care Center 1.0
	 *
	 * @param array $block_patterns List of block patterns by name.
	 */
	$patterns = apply_filters( 'vet_care_center_block_patterns', $patterns );

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = vet_care_center_get_pattern_content( $block_pattern );
		register_block_pattern(
			'vet-care-center/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'vet_care_center_register_block_patterns', 9 );
