<?php
$chapters = new WP_Query(array(
	'post_type' => 'parcours',
	'posts_per_page' => -1,
	'orderby' => 'menu_order',
	'order' => 'ASC',
	'status' => 'publish',
	'post_parent'    => get_queried_object_id(),
));


$otherSteps = new WP_Query(array(
	'post_type' => 'parcours',
	'posts_per_page' => -1,
	'orderby' => 'menu_order',
	'order' => 'ASC',
	'status' => 'publish',
	'post_parent'    => 0,
	'post__not_in' => array(get_queried_object_id())
));

$blocks = parse_blocks($post->post_content);
$chapterBlockIndex  = build_page_chapter_index($blocks); // see utilities.php
?>

<nav class=" breadcrumbs_navigation" aria-label="<?php echo __("Vous êtes ici", "homegrade-theme__texte-fonctionnel") ?>">
	<?php
	$archiveParcours = get_page_by_template('template-parcours-renovateur.php')[0];
	?>
	<ol>
		<li>
			<a href="<?php echo home_url() ?>" title="<?php echo __("Accueil", "homegrade-theme__texte-fonctionnel") ?>">
				<img src="<?php echo get_template_directory_uri() . "/resources/img/pictogrammes/icon_house_dark.svg" ?>" alt="">
			</a>
		</li>
		<li><a href="<?php echo get_post_permalink($archiveParcours)  ?>"><?php echo $archiveParcours->post_title ?></a></li>
		<li><a href="<?php echo the_permalink()  ?>" aria-current="location" aria-disabled="true"><?php echo get_queried_object()->post_title ?></a></li>

	</ol>
</nav>


<?php
$pageIcon = get_field('page_icon', $archiveParcours->ID);
get_template_part("template-components/heading-box--parcours-parent", null, array(
	"pageIcon" => $pageIcon,
	"subtitle" =>  __("Parcours rénovateur", "homegrade-theme__texte-fonctionnel"),
	"title" =>  get_the_title(),
	"icon" => $pageIcon,
));
?>

<div class="parcours-content-wrapper conseils_wrapper">

	<aside>
		<div class="parcours-steps">
			<div class="current-steps-index">
				<?php if ($chapterBlockIndex) : ?>
					<div class="chapter_index__titling">
						<div class="icon">
							<img src="<?php echo get_template_directory_uri() . '/resources/img/graphic-assets/icon-feather-menu.svg' ?>" alt="">
						</div>
						<h2 class="chapter_index__title"> <?php echo __("Dans ce conseil", "homegrade-theme__texte-fonctionnel") ?> </h2>
					</div>
					<ul class="chapter_index__list">
						<div class="chapter_index__position-indicator"></div>
						<?php foreach ($chapterBlockIndex  as $chapter) : ?>
							<li class="chapter_index__link"><a href="<?php echo $chapter['anchor'] ?>"><?php echo $chapter['title'] ?></a></li>
						<?php endforeach; ?>
					</ul>
				<?php endif; ?>
			</div>

			<?php foreach ($otherSteps->posts as $otherStep) : ?>
				<a class="parcours-other-steps-suggestion" href="<?php echo get_the_permalink($otherStep->ID) ?>">
					<?php

					$stepIcon = get_field('step_icon', $otherStep->ID);
					?>
					<?php if ($stepIcon) : ?>
						<img class="step-icon" src="<?php echo $stepIcon['url'] ?>" alt="">
					<?php endif; ?>
					<span><?php echo $otherStep->post_title ?></span>
				</a>
			<?php endforeach; ?>
		</div>
	</aside>


	<article class="container my-8 mx-auto entry-content single-editor-content">
		<?php
		the_content();
		?>


	</article>
</div>