<?php
/**
 * IT Software Technology: Block Patterns
 *
 * @since IT Software Technology 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function it_software_technology_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 IT Software Technology 1.0
 *
 * @return void
 */
function it_software_technology_register_block_patterns() {

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

	$block_pattern_categories = array(
		'it-software-technology-footers' => array( 'label' => __( 'Footers Section', 'it-software-technology' ) ),
		'it-software-technology-headers' => array( 'label' => __( 'Headers Section', 'it-software-technology' ) ),
		'it-software-technology-pages'   => array( 'label' => __( 'Pages', 'it-software-technology' ) ),
		'it-software-technology-query'   => array( 'label' => __( 'Query', 'it-software-technology' ) ),
		'it-software-technology-sidebars'   => array( 'label' => __( 'Sidebars', 'it-software-technology' ) ),
		'it-software-technology-banner'   => array( 'label' => __( 'Slider Section', 'it-software-technology' ) ),
		'it-software-technology-about-section'   => array( 'label' => __( 'About Section', 'it-software-technology' ) ),
		'it-software-technology-counter-section'   => array( 'label' => __( 'Counter Section', 'it-software-technology' ) ),
		'it-software-technology-latest-blog-section'   => array( 'label' => __( 'Latest Blog Section', 'it-software-technology' ) ),
		'it-software-technology-comment-section'   => array( 'label' => __( 'Comment Section', 'it-software-technology' ) ),
		'it-software-technology-theme-button'   => array( 'label' => __( 'Theme Button Section', 'it-software-technology' ) ),
	);

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

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = it_software_technology_get_pattern_content( $block_pattern );
		register_block_pattern(
			'it-software-technology/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'it_software_technology_register_block_patterns', 9 );
