<?php
/*
Name: Standard Curated Posts
Description: Display a curated collection of posts, styled as a standard card group
Curated Sections: 1
Default: true
*/

declare(strict_types=1);

use WP_AUX\Services\AuxCF\BlocksService;
use WP_AUX\Services\PostService;

$section = BlocksService::getSection('card-group');

$posts = aux_get_field('curated_collection_posts');
$postCount = !empty($posts) ? count($posts) : 0;

$cards = '';
if ($posts) {
  foreach ($posts as $post) {
    $cards .= PostService::postCard($post, false, true);
  }
}

$section->setContent(<<<HTML
  <div class="card-container" data-cards="$postCount">
    $cards
  </div>
HTML);

echo $section;
