<?php
$wrapper_attributes = get_block_wrapper_attributes(array('class' => 'story-timeline'));

$years = array();
if (isset($block) && is_object($block) && ! empty($block->inner_blocks)) {
	foreach ($block->inner_blocks as $inner_block) {
		if (isset($inner_block->name) && $inner_block->name === 'carhop-blocks/story-timeline-step') {
			$y = isset($inner_block->attributes['year']) ? $inner_block->attributes['year'] : null;
			if ($y !== null && $y !== '') {
				$years[] = $y;
			}
		}
	}
}
?>

<section <?php echo $wrapper_attributes; ?>>
	<aside class="story-timeline__years">
		<ul>
			<?php foreach ($years as $y) : ?>
				<li class="story-timeline__year"><a href="#year-<?php echo esc_attr($y); ?>"><?php echo esc_html($y); ?></a></li>
			<?php endforeach; ?>
		</ul>
	</aside>
	<div class="story-timeline__innerblocks" id="<?php echo esc_attr($years[0]); ?>">
		<?php echo $content; ?>
	</div>
</section>