<?php
/**
 * Influencer Agency: Block Patterns
 *
 * @since Influencer Agency 1.0
 */

 /**
  * Get patterns content.
  *
  * @param string $file_name Filename.
  * @return string
  */
function influencer_agency_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 Influencer Agency 1.0
 *
 * @return void
 */
function influencer_agency_register_block_patterns() {

	$patterns = array(
		'header-default' => array(
			'title'      => __( 'Default header', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-headers' ),
			'blockTypes' => array( 'parts/header' ),
		),
		'footer-default' => array(
			'title'      => __( 'Default footer', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-footers' ),
			'blockTypes' => array( 'parts/footer' ),
		),
		'home-banner' => array(
			'title'      => __( 'Home Banner', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-banner' ),
		),
		'brand-section' => array(
			'title'      => __( 'Brand Sections', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-brand-section' ),
		),
		'choose-us-section' => array(
			'title'      => __( 'Choose Us Section', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-choose-us-section' ),
		),
		'meet-influencer' => array(
			'title'      => __( 'Meet Influencer Section', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-meet-influencer' ),
		),
		'primary-sidebar' => array(
			'title'    => __( 'Primary Sidebar', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-sidebars' ),
		),
		'hidden-404' => array(
			'title'    => __( '404 content', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-pages' ),
		),
		'post-listing-single-column' => array(
			'title'    => __( 'Post Single Column', 'influencer-agency' ),
			//'inserter' => false,
			'categories' => array( 'influencer-agency-query' ),
		),
		'post-listing-two-column' => array(
			'title'    => __( 'Post Two Column', 'influencer-agency' ),
			//'inserter' => false,
			'categories' => array( 'influencer-agency-query' ),
		),
		'post-listing-three-column' => array(
			'title'    => __( 'Post Three Column', 'influencer-agency' ),
			//'inserter' => false,
			'categories' => array( 'influencer-agency-query' ),
		),
		'post-listing-four-column' => array(
			'title'    => __( 'Post Four Column', 'influencer-agency' ),
			//'inserter' => false,
			'categories' => array( 'influencer-agency-query' ),
		),
		'feature-post-column' => array(
			'title'    => __( 'Feature Post Column', 'influencer-agency' ),
			//'inserter' => false,
			'categories' => array( 'influencer-agency-query' ),
		),
		'comment-section-1' => array(
			'title'    => __( 'Comment Section 1', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-comment-sections' ),
		),
		'cover-with-post-title' => array(
			'title'    => __( 'Cover With Post Title', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-banner-sections' ),
		),
		'theme-button' => array(
			'title'    => __( 'Theme Button', 'influencer-agency' ),
			'categories' => array( 'influencer-agency-theme-button' ),
		),
	);

	$block_pattern_categories = array(
		'influencer-agency-footers' => array( 'label' => __( 'Footers', 'influencer-agency' ) ),
		'influencer-agency-headers' => array( 'label' => __( 'Headers', 'influencer-agency' ) ),
		'influencer-agency-pages'   => array( 'label' => __( 'Pages', 'influencer-agency' ) ),
		'influencer-agency-query'   => array( 'label' => __( 'Query', 'influencer-agency' ) ),
		'influencer-agency-sidebars'   => array( 'label' => __( 'Sidebars', 'influencer-agency' ) ),
		'influencer-agency-banner'   => array( 'label' => __( 'Banner Sections', 'influencer-agency' ) ),
		'influencer-agency-brand-section'   => array( 'label' => __( 'Brand Section Sections', 'influencer-agency' ) ),
		'influencer-agency-choose-us-section'   => array( 'label' => __( 'Choose Us Sections', 'influencer-agency' ) ),
		'influencer-agency-meet-influencer'   => array( 'label' => __( 'Meet Influencer Section', 'influencer-agency' ) ),
		'influencer-agency-comment-section'   => array( 'label' => __( 'Comment Sections', 'influencer-agency' ) ),
		'influencer-agency-theme-button'   => array( 'label' => __( 'Theme Button Sections', 'influencer-agency' ) ),
	);

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

	foreach ( $patterns as $block_pattern => $pattern ) {
		$pattern['content'] = influencer_agency_get_pattern_content( $block_pattern );
		register_block_pattern(
			'influencer-agency/' . $block_pattern,
			$pattern
		);
	}
}
add_action( 'init', 'influencer_agency_register_block_patterns', 9 );
