<?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 dulcie
 */

defined( 'ABSPATH' ) || exit;

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

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

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

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

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

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

	register_block_pattern_category(
		'dulcie',
		array( 'label' => __( 'Dulcie', 'dulcie' ) )
	);

	register_block_pattern(
		'dulcie/intro',
		array(
			'title'      => __( 'Post introduction', 'dulcie' ),
			'categories' => array( 'dulcie', 'text' ),
			'content'    => '<!-- wp:heading {"level":2} --><h2>'
				. esc_html__( 'A heading to open with', 'dulcie' )
				. '</h2><!-- /wp:heading -->'
				. '<!-- wp:paragraph {"className":"is-style-dulcie-lead"} --><p class="is-style-dulcie-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.', 'dulcie' )
				. '</p><!-- /wp:paragraph -->',
		)
	);

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

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