<?php
/**
 * Block patterns and block styles.
 *
 * style.css has advertised the block-patterns and block-styles tags since the
 * theme was published, without ever registering either. This provides them,
 * using the theme's own typography and colour choices.
 *
 * @package Promos
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'promos_register_block_patterns' ) ) :
	/**
	 * Register the pattern category and the patterns themselves.
	 */
	function promos_register_block_patterns() {

		if ( ! function_exists( 'register_block_pattern' ) ) {
			return;
		}

		if ( function_exists( 'register_block_pattern_category' ) ) {
			register_block_pattern_category(
				'promos',
				array( 'label' => __( 'Promos', 'promos' ) )
			);
		}

		register_block_pattern(
			'promos/hero-heading',
			array(
				'title'      => __( 'Hero heading with intro', 'promos' ),
				'categories' => array( 'promos', 'header' ),
				'content'    => '<!-- wp:group {"align":"wide"} --><div class="wp-block-group alignwide">'
					. '<!-- wp:heading {"level":1,"textAlign":"center"} -->'
					. '<h1 class="wp-block-heading has-text-align-center">' . esc_html__( 'Tell your story', 'promos' ) . '</h1>'
					. '<!-- /wp:heading -->'
					. '<!-- wp:paragraph {"align":"center"} -->'
					. '<p class="has-text-align-center">' . esc_html__( 'A short introduction that sets up the article below. Replace this with your own words.', 'promos' ) . '</p>'
					. '<!-- /wp:paragraph -->'
					. '</div><!-- /wp:group -->',
			)
		);

		register_block_pattern(
			'promos/two-column-text',
			array(
				'title'      => __( 'Two column text', 'promos' ),
				'categories' => array( 'promos', 'text' ),
				'content'    => '<!-- wp:columns {"align":"wide"} --><div class="wp-block-columns alignwide">'
					. '<!-- wp:column --><div class="wp-block-column">'
					. '<!-- wp:heading {"level":3} --><h3 class="wp-block-heading">' . esc_html__( 'First column', 'promos' ) . '</h3><!-- /wp:heading -->'
					. '<!-- wp:paragraph --><p>' . esc_html__( 'Describe one idea here.', 'promos' ) . '</p><!-- /wp:paragraph -->'
					. '</div><!-- /wp:column -->'
					. '<!-- wp:column --><div class="wp-block-column">'
					. '<!-- wp:heading {"level":3} --><h3 class="wp-block-heading">' . esc_html__( 'Second column', 'promos' ) . '</h3><!-- /wp:heading -->'
					. '<!-- wp:paragraph --><p>' . esc_html__( 'And a second idea here.', 'promos' ) . '</p><!-- /wp:paragraph -->'
					. '</div><!-- /wp:column -->'
					. '</div><!-- /wp:columns -->',
			)
		);

		register_block_pattern(
			'promos/pull-quote',
			array(
				'title'      => __( 'Highlighted quote', 'promos' ),
				'categories' => array( 'promos', 'text' ),
				'content'    => '<!-- wp:quote {"className":"is-style-promos-bordered"} -->'
					. '<blockquote class="wp-block-quote is-style-promos-bordered">'
					. '<!-- wp:paragraph --><p>' . esc_html__( 'A line worth pulling out of the body copy.', 'promos' ) . '</p><!-- /wp:paragraph -->'
					. '<cite>' . esc_html__( 'Attribution', 'promos' ) . '</cite>'
					. '</blockquote><!-- /wp:quote -->',
			)
		);
	}
endif;
add_action( 'init', 'promos_register_block_patterns' );

if ( ! function_exists( 'promos_register_block_styles' ) ) :
	/**
	 * Register the theme's block style variations.
	 */
	function promos_register_block_styles() {

		if ( ! function_exists( 'register_block_style' ) ) {
			return;
		}

		register_block_style(
			'core/quote',
			array(
				'name'  => 'promos-bordered',
				'label' => __( 'Bordered', 'promos' ),
			)
		);

		register_block_style(
			'core/image',
			array(
				'name'  => 'promos-rounded',
				'label' => __( 'Rounded', 'promos' ),
			)
		);

		register_block_style(
			'core/separator',
			array(
				'name'  => 'promos-wide-rule',
				'label' => __( 'Wide rule', 'promos' ),
			)
		);
	}
endif;
add_action( 'init', 'promos_register_block_styles' );
