<?php
/**
 * Block styles and block patterns.
 *
 * Both are registered on init rather than at file scope: registering them any
 * earlier calls the translation functions before the text domain is loaded,
 * which WordPress 6.7 and later reports as a _load_textdomain_just_in_time
 * notice.
 *
 * @package lively
 */

defined( 'ABSPATH' ) || exit;

/**
 * Register the theme's block styles.
 *
 * @return void
 */
function lively_register_block_styles() {

	register_block_style(
		'core/paragraph',
		array(
			'name'  => 'lively-lead',
			'label' => __( 'Lead paragraph', 'lively' ),
		)
	);

	register_block_style(
		'core/group',
		array(
			'name'  => 'lively-boxed',
			'label' => __( 'Boxed', 'lively' ),
		)
	);

	register_block_style(
		'core/list',
		array(
			'name'  => 'lively-plain-list',
			'label' => __( 'Plain', 'lively' ),
		)
	);
}
add_action( 'init', 'lively_register_block_styles' );

/**
 * Register the theme's block patterns.
 *
 * @return void
 */
function lively_register_block_patterns() {

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

	register_block_pattern_category(
		'lively',
		array( 'label' => __( 'Lively', 'lively' ) )
	);

	register_block_pattern(
		'lively/intro',
		array(
			'title'      => __( 'Post introduction', 'lively' ),
			'categories' => array( 'lively', 'text' ),
			'content'    => '<!-- wp:heading {"level":2} --><h2>'
				. esc_html__( 'A heading to open with', 'lively' )
				. '</h2><!-- /wp:heading -->'
				. '<!-- wp:paragraph {"className":"is-style-lively-lead"} --><p class="is-style-lively-lead">'
				. esc_html__( 'Open the post with a paragraph that says what it is about. This one is set a little larger than the body text so it reads as a standfirst.', 'lively' )
				. '</p><!-- /wp:paragraph -->',
		)
	);

	register_block_pattern(
		'lively/pull-quote',
		array(
			'title'      => __( 'Quote and attribution', 'lively' ),
			'categories' => array( 'lively', 'text' ),
			'content'    => '<!-- wp:quote --><blockquote class="wp-block-quote"><p>'
				. esc_html__( 'A sentence worth setting apart from the paragraphs around it.', 'lively' )
				. '</p><cite>'
				. esc_html__( 'Someone worth quoting', 'lively' )
				. '</cite></blockquote><!-- /wp:quote -->',
		)
	);

	register_block_pattern(
		'lively/two-column-note',
		array(
			'title'      => __( 'Boxed note, two columns', 'lively' ),
			'categories' => array( 'lively', 'text' ),
			'content'    => '<!-- wp:group {"className":"is-style-lively-boxed"} --><div class="wp-block-group is-style-lively-boxed">'
				. '<!-- wp:columns --><div class="wp-block-columns">'
				. '<!-- wp:column --><div class="wp-block-column">'
				. '<!-- wp:heading {"level":3} --><h3>'
				. esc_html__( 'On the left', 'lively' )
				. '</h3><!-- /wp:heading -->'
				. '<!-- wp:paragraph --><p>'
				. esc_html__( 'A short note, an aside, or a summary of what came before.', 'lively' )
				. '</p><!-- /wp:paragraph -->'
				. '</div><!-- /wp:column -->'
				. '<!-- wp:column --><div class="wp-block-column">'
				. '<!-- wp:heading {"level":3} --><h3>'
				. esc_html__( 'On the right', 'lively' )
				. '</h3><!-- /wp:heading -->'
				. '<!-- wp:paragraph --><p>'
				. esc_html__( 'And the other half of the pair, in the same boxed panel.', 'lively' )
				. '</p><!-- /wp:paragraph -->'
				. '</div><!-- /wp:column -->'
				. '</div><!-- /wp:columns -->'
				. '</div><!-- /wp:group -->',
		)
	);
}
add_action( 'init', 'lively_register_block_patterns' );
