<?php
/**
 * Alert Banner block — server-side render.
 *
 * @var array    $attributes Block attributes.
 * @var string   $content    Block content.
 * @var WP_Block $block      Block instance.
 *
 * @package Northfield_Theatre
 * @since 1.0.0
 */

$message     = $attributes['message'] ?? '';
$type        = $attributes['type'] ?? 'info';
$dismissible = $attributes['dismissible'] ?? true;

if ( empty( $message ) ) {
	return;
}

$type_classes = array(
	'info'    => '',
	'warning' => 'alert-banner--warning',
	'urgent'  => 'alert-banner--urgent',
);

$extra_class = isset( $type_classes[ $type ] ) ? $type_classes[ $type ] : '';
?>
<div <?php echo get_block_wrapper_attributes( array(
	'class' => 'alert-banner ' . $extra_class,
	'role'  => 'alert',
	'id'    => 'alert-banner',
) ); ?>>
	<div class="alert-banner__inner container">
		<p class="alert-banner__message">
			<?php echo wp_kses_post( $message ); ?>
		</p>
		<?php if ( $dismissible ) : ?>
			<button class="alert-banner__dismiss"
			        id="alert-banner-dismiss"
			        aria-label="<?php esc_attr_e( 'Dismiss alert', 'northfield-theatre' ); ?>">
				<?php echo northfield_icon( 'close', 18 ); ?>
			</button>
		<?php endif; ?>
	</div>
</div>
