<?php

$parentTitle = get_the_title($post->post_parent) ?? null;
$parentUrl = get_the_permalink($post->post_parent) ?? null;
$pageIcon = get_field('step_icon', $post->ID);
?>

<div class="post-parcours-page-container">
	<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 $parentUrl ?>"><?php echo $parentTitle ?></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 /* --------
					HEADING BOX
			---------------*/ ?>
	<?php
	get_template_part("template-components/heading-box--parcours-single", null, array(
		"parent_title" => $parentTitle,
		"title" => get_the_title(),
		"page_icon" => $pageIcon,
		"published" => get_the_date()
	));
	?>
	<article class="container my-8 mx-auto entry-content single-editor-content <?php echo $thematiqueColorSlug ? "entry-content--" . $thematiqueColorSlug : "" ?>">
		<?php the_content() ?>
	</article>

	<!-- PREVIOUS / NEXT ARTICLES -->
	<div class="previous-next-posts">
		<?php

		$prev_post = get_previous_post() ?? null;
		$next_post = get_next_post() ?? null;
		$prev_thumbnail_url = get_the_post_thumbnail_url($prev_post, 'thumbnail');
		$prev_page_icon = get_field('step_icon', $prev_post->ID) ?? null;
		$next_page_icon = get_field('step_icon', $next_post->ID) ?? null;

		$test = get_parcours_previous_next_posts($post);
		?>
		<?php if ($prev_post) : ?>
			<a class="previous-next-parcours__previous" href="<?php echo get_the_permalink($prev_post->ID) ?>">

				<div class="previous-next-parcours__link-content">
					<p class="post_denomination"><?php echo __("Étape précédente ", "homegrade-theme__texte-fonctionnel") ?></p>
					<p class="post_title"><?php echo $prev_post->post_title ?></p>
				</div>
				<img class="page_icon" src="<?php echo $prev_page_icon['url'] ?>" alt="">
			</a>
		<?php endif; ?>

		<?php if ($next_post) : ?>
			<a class="previous-next-parcours__next" href="<?php echo get_the_permalink($next_post->ID) ?>">
				<img class="page_icon" src="<?php echo $next_page_icon['url'] ?>" alt="">
				<div class="previous-next-parcours__link-content">
					<p class="post_denomination"><?php echo __("Étape suivante ", "homegrade-theme__texte-fonctionnel") ?></p>
					<p class="post_title"><?php echo $next_post->post_title ?></p>
				</div>

			</a>
		<?php endif; ?>

	</div>

</div>