<?php
/**
 * Hair Dresser and Salon: Block Patterns
 *
 * @since Hair Dresser and Salon 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function hair_dresser_and_salon_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 Hair Dresser and Salon 1.0
 *
 * @return void
 */
function hair_dresser_and_salon_register_block_patterns() {

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

	$block_pattern_categories = array(
		'hair-dresser-and-salon-footers' => array( 'label' => __( 'Footers Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-headers' => array( 'label' => __( 'Headers Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-pages'   => array( 'label' => __( 'Pages', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-query'   => array( 'label' => __( 'Query', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-sidebars'   => array( 'label' => __( 'Sidebars', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-banner'   => array( 'label' => __( 'Slider Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-team-section'   => array( 'label' => __( 'Team Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-gallery-section'   => array( 'label' => __( 'Gallery Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-latest-blog-section'   => array( 'label' => __( 'Latest Blog Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-comment-section'   => array( 'label' => __( 'Comment Section', 'hair-dresser-and-salon' ) ),
		'hair-dresser-and-salon-theme-button'   => array( 'label' => __( 'Theme Button Section', 'hair-dresser-and-salon' ) ),
	);

	/**
	 * Filters the theme block pattern categories.
	 *
	 * @since Hair Dresser and Salon 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( 'hair_dresser_and_salon_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 Hair Dresser and Salon 1.0
	 *
	 * @param array $block_patterns List of block patterns by name.
	 */
	$patterns = apply_filters( 'hair_dresser_and_salon_block_patterns', $patterns );

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = hair_dresser_and_salon_get_pattern_content( $block_pattern );
		register_block_pattern(
			'hair-dresser-and-salon/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'hair_dresser_and_salon_register_block_patterns', 9 );
