<?php
/**
 * Corporate Consultancy: Block Patterns
 *
 * @since Corporate Consultancy 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function corporate_consultancy_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 Corporate Consultancy 1.0
 *
 * @return void
 */
function corporate_consultancy_register_block_patterns() {

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

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

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

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = corporate_consultancy_get_pattern_content( $block_pattern );
		register_block_pattern(
			'corporate-consultancy/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'corporate_consultancy_register_block_patterns', 9 );
