<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
 * Dynamic render for brentwood/tagline — the live site's p.tag-line as a block.
 *
 * Dynamic (not a static save) so the inline highlight HTML never trips block
 * validation across edits, and so the stored RichText is re-sanitised on output.
 *
 * @var array $attributes
 */
$align_ok = array( 'left', 'center', 'right' );
$align    = isset( $attributes['align'] ) && in_array( $attributes['align'], $align_ok, true )
	? $attributes['align'] : 'left';

$text_color = isset( $attributes['textColor'] ) ? sanitize_hex_color( $attributes['textColor'] ) : '';
$hl         = isset( $attributes['highlightColor'] ) ? sanitize_hex_color( $attributes['highlightColor'] ) : '';
if ( ! $hl ) { $hl = '#c8272c'; }

// Re-sanitise the stored RichText to the inline formats the editor allows:
// bold/italic (<strong>/<em>), links, and the highlight span (.bw-tag-hl).
$text = isset( $attributes['text'] ) ? (string) $attributes['text'] : '';
$text = wp_kses(
	$text,
	array(
		'a'      => array( 'href' => array(), 'class' => array(), 'target' => array(), 'rel' => array() ),
		'strong' => array(),
		'b'      => array(),
		'em'     => array(),
		'i'      => array(),
		'br'     => array(),
		'span'   => array( 'class' => array() ),
		'mark'   => array( 'class' => array() ),
	)
);

// Nothing to show if the tagline is empty (avoids an empty <p> on the page).
if ( '' === trim( wp_strip_all_tags( $text ) ) ) {
	return '';
}

$style = '--bw-tag-hl:' . esc_attr( $hl ) . ';text-align:' . esc_attr( $align ) . ';';
if ( $text_color ) {
	$style .= 'color:' . esc_attr( $text_color ) . ';';
}

$wrapper = get_block_wrapper_attributes(
	array(
		'class' => 'bw-tagline',
		'style' => $style,
	)
);

echo '<p ' . $wrapper . '>' . $text . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput
