<?php
/**
 * Expert Travel Agent: Block Patterns
 *
 * @since Expert Travel Agent 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function expert_travel_agent_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 Expert Travel Agent 1.0
 *
 * @return void
 */
function expert_travel_agent_register_block_patterns() {

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

	$block_pattern_categories = array(
		'expert-travel-agent-footers' => array( 'label' => __( 'Footers Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-headers' => array( 'label' => __( 'Headers Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-pages'   => array( 'label' => __( 'Pages', 'expert-travel-agent' ) ),
		'expert-travel-agent-query'   => array( 'label' => __( 'Query', 'expert-travel-agent' ) ),
		'expert-travel-agent-sidebars'   => array( 'label' => __( 'Sidebars', 'expert-travel-agent' ) ),
		'expert-travel-agent-banner'   => array( 'label' => __( 'Slider Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-location-section'   => array( 'label' => __( 'Location Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-latest-blog-section'   => array( 'label' => __( 'Latest Blog Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-gallery-section'   => array( 'label' => __( 'Gallery Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-comment-section'   => array( 'label' => __( 'Comment Section', 'expert-travel-agent' ) ),
		'expert-travel-agent-theme-button'   => array( 'label' => __( 'Theme Button Section', 'expert-travel-agent' ) ),
	);

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

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = expert_travel_agent_get_pattern_content( $block_pattern );
		register_block_pattern(
			'expert-travel-agent/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'expert_travel_agent_register_block_patterns', 9 );
