<?php
/**
 * Template part for displaying related posts in the footer of the main body of a page.
 *
 * @package MarComm-AUX
 * @since 1.0.0
 */
declare(strict_types=1);

use WP_AUX\Entities\AuxFramework\Partials\CardGroupEntity;
use WP_AUX\Enum\CardsLayoutEnum;
use WP_AUX\Services\AuxFramework\CardGroupService;
use WP_AUX\Services\PostService;

/**
 * Related posts in the footer of the main body of a page
 * @since 1.0.0
 */

$relatedPosts = aux_related_posts(['post_tag', 'category']);
$relatedPosts->setManuallySelectedPosts(
  (array) aux_page_builder_setting('related_posts')
);

if (!count($relatedPosts)) {
  return;
}

$label = PostService::getTypeLabelForPost();

$cardGroup = CardGroupEntity::create(CardsLayoutEnum::Standard)
  ->setHeading('Related ' . $label)
  ->setCardsCtaType('standard')
  ->addCta([
    'url' => get_post_type_archive_link(get_post_type()),
    'title' => 'View All ' . $label,
  ]);

CardGroupService::addPostsToCardGroup($cardGroup, $relatedPosts);
?>
<aside id="footer-related-<?php echo get_post_type(); ?>" class="aux-container--fluid-mw footer-related">
  <?php echo $cardGroup; ?>
</aside>
