<?php
/**
 * Hero Gallery block — server-side render.
 *
 * @var array    $attributes Block attributes.
 * @var string   $content    Block content (empty for dynamic blocks).
 * @var WP_Block $block      Block instance.
 *
 * @package Northfield_Theatre
 * @since 1.0.0
 */

$heading  = ! empty( $attributes['heading'] ) ? $attributes['heading'] : __( 'Welcome to Northfield Theatre', 'northfield-theatre' );
$subtitle = ! empty( $attributes['subtitle'] ) ? $attributes['subtitle'] : get_bloginfo( 'description' );
$cta_text = ! empty( $attributes['ctaText'] ) ? $attributes['ctaText'] : __( 'Explore the new season', 'northfield-theatre' );
$cta_url  = ! empty( $attributes['ctaUrl'] ) ? $attributes['ctaUrl'] : home_url( '/whats-on/' );

// Split heading at line break if present.
$heading_parts = explode( '\n', $heading );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'hero' ) ); ?>
         aria-label="<?php echo esc_attr( wp_strip_all_tags( $heading ) ); ?>">
	<div class="hero__backdrop">
		<div class="hero__slide hero__slide--active" aria-hidden="true"></div>
	</div>
	<div class="hero__overlay"></div>
	<div class="hero__content container">
		<h2 class="hero__title">
			<?php echo wp_kses_post( nl2br( esc_html( $heading ) ) ); ?>
		</h2>
		<?php if ( $subtitle ) : ?>
			<p class="hero__subtitle"><?php echo esc_html( $subtitle ); ?></p>
		<?php endif; ?>
		<?php if ( $cta_text && $cta_url ) : ?>
			<a href="<?php echo esc_url( $cta_url ); ?>" class="btn btn--primary btn--lg hero__cta">
				<?php echo esc_html( $cta_text ); ?>
			</a>
		<?php endif; ?>
	</div>
</section>
