<?php
$relatedPostId = $attributes['relatedPostId'] ?? null;
$postType = get_post_type_object(get_post_type($relatedPostId));

$relatedPost = get_post($relatedPostId) ?? null;
$relatedPostUrl = get_permalink($relatedPostId) ?? null;

$postThumbnail =  get_the_post_thumbnail_url($relatedPostId) ?? null;
$target = $postType->name === 'fiches-infos' ? "_blank" : "_self";
$thematique = get_the_terms($relatedPostId, 'thematiques')[0];
$mainThematique = getMainThematique($thematique);
$thematiqueColorSlug = $mainThematique->slug;
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];

$postDescription = $attributes['postDescription'] ?? null;

$coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail  ? $postThumbnail : ($thematique_icon ? $thematique_icon['url'] : null);

$thematiqueColorSlug = getThematiqueFamilySlug($mainThematique->slug);
$target = $postType->name === 'brochures' ? "_blank" : "_self";
?>
<a class="post-card post-card--<?php echo $mainThematique->slug ?>" href="<?php echo $relatedPostUrl ?>" target="<?php echo $target ?>">

	<img class="post-card__cover post-card__cover--<?php echo $postType->name ?>" src="<?php echo $coverUrl ?>" alt="">

	<div class="post-card__details">
		<div class="post-card__tags">
			<?php if ($mainThematique) : ?>
				<div class="tag thematique-tag thematique-tag--<?php echo $mainThematique->slug ?>"><?php echo $mainThematique->name  ?></div>
			<?php endif; ?>
			<div class="tag post-type-tag"><?php echo $postType->label ?></div>
		</div>
		<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
		<?php if ($postDescription): ?>
			<p><?php echo $postDescription ?></p>
		<?php endif; ?>
		<p></p>
	</div>
</a>