<?php
/**
 * Veterinary Hospital: Block Patterns
 *
 * @since Veterinary Hospital 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function veterinary_hospital_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 Veterinary Hospital 1.0
 *
 * @return void
 */
function veterinary_hospital_register_block_patterns() {

	$patterns = array(
		'header-default' => array(
			'title'      => __( 'Default header', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-headers' ),
			'blockTypes' => array( 'parts/header' ),
		),
		'footer-default' => array(
			'title'      => __( 'Default footer', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-footers' ),
			'blockTypes' => array( 'parts/footer' ),
		),
		'home-banner' => array(
			'title'      => __( 'Home Banner', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-banner' ),
		),
		'our-speciality-section' => array(
			'title'      => __( 'Our Speciality Section', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-our-speciality-section' ),
		),
		'about-us-section' => array(
			'title'      => __( 'About Us Section', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-about-us-section' ),
		),
		'testimonial-section' => array(
			'title'      => __( 'Testimonial Section', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-testimonial-section' ),
		),
		'news-section' => array(
			'title'      => __( 'News Section', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-news-section' ),
		),
		'faq-section' => array(
			'title'      => __( 'FAQ Section', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-faq-section' ),
		),
		'primary-sidebar' => array(
			'title'    => __( 'Primary Sidebar', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-sidebars' ),
		),
		'hidden-404' => array(
			'title'    => __( '404 content', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-pages' ),
		),
		'post-listing-single-column' => array(
			'title'    => __( 'Post Single Column', 'veterinary-hospital' ),
			//'inserter' => false,
			'categories' => array( 'veterinary-hospital-query' ),
		),
		'post-listing-two-column' => array(
			'title'    => __( 'Post Two Column', 'veterinary-hospital' ),
			//'inserter' => false,
			'categories' => array( 'veterinary-hospital-query' ),
		),
		'post-listing-three-column' => array(
			'title'    => __( 'Post Three Column', 'veterinary-hospital' ),
			//'inserter' => false,
			'categories' => array( 'veterinary-hospital-query' ),
		),
		'post-listing-four-column' => array(
			'title'    => __( 'Post Four Column', 'veterinary-hospital' ),
			//'inserter' => false,
			'categories' => array( 'veterinary-hospital-query' ),
		),
		'feature-post-column' => array(
			'title'    => __( 'Feature Post Column', 'veterinary-hospital' ),
			//'inserter' => false,
			'categories' => array( 'veterinary-hospital-query' ),
		),
		'comment-section-1' => array(
			'title'    => __( 'Comment Section 1', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-comment-sections' ),
		),
		'cover-with-post-title' => array(
			'title'    => __( 'Cover With Post Title', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-banner-sections' ),
		),
		'cover-with-search-title' => array(
			'title'    => __( 'Cover With Search Title', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-banner-sections' ),
		),
		'cover-with-archive-title' => array(
			'title'    => __( 'Cover With Archive Title', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-banner-sections' ),
		),
		'cover-with-index-title' => array(
			'title'    => __( 'Cover With Index Title', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-banner-sections' ),
		),
		'theme-button' => array(
			'title'    => __( 'Theme Button', 'veterinary-hospital' ),
			'categories' => array( 'veterinary-hospital-theme-button' ),
		),
	);

	$block_pattern_categories = array(
		'veterinary-hospital-footers' => array( 'label' => __( 'Footers', 'veterinary-hospital' ) ),
		'veterinary-hospital-headers' => array( 'label' => __( 'Headers', 'veterinary-hospital' ) ),
		'veterinary-hospital-pages'   => array( 'label' => __( 'Pages', 'veterinary-hospital' ) ),
		'veterinary-hospital-query'   => array( 'label' => __( 'Query', 'veterinary-hospital' ) ),
		'veterinary-hospital-sidebars'   => array( 'label' => __( 'Sidebars', 'veterinary-hospital' ) ),
		'veterinary-hospital-banner'   => array( 'label' => __( 'Banner Sections', 'veterinary-hospital' ) ),
		'veterinary-hospital-our-speciality-section'   => array( 'label' => __( 'Our Speciality Section', 'veterinary-hospital' ) ),
		'veterinary-hospital-about-us-section'   => array( 'label' => __( 'About Us Section', 'veterinary-hospital' ) ),
		'veterinary-hospital-testimonial-section'   => array( 'label' => __( 'Testimonial Section', 'veterinary-hospital' ) ),
		'veterinary-hospital-news-section'   => array( 'label' => __( 'News Section', 'veterinary-hospital' ) ),
		'veterinary-hospital-faq-section'   => array( 'label' => __( 'FAQ Section', 'veterinary-hospital' ) ),
		'veterinary-hospital-comment-section'   => array( 'label' => __( 'Comment Sections', 'veterinary-hospital' ) ),
		'veterinary-hospital-theme-button'   => array( 'label' => __( 'Theme Button Sections', 'veterinary-hospital' ) ),
	);

	/**
	 * Filters the theme block pattern categories.
	 *
	 * @since Veterinary Hospital 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( 'veterinary_hospital_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 Veterinary Hospital 1.0
	 *
	 * @param array $block_patterns List of block patterns by name.
	 */
	$patterns = apply_filters( 'veterinary_hospital_block_patterns', $patterns );

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = veterinary_hospital_get_pattern_content( $block_pattern );
		register_block_pattern(
			'veterinary-hospital/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'veterinary_hospital_register_block_patterns', 9 );
