<?php
/**
 * Frontend output for the AUX Card Slab component
 * AUX documentation: https://aggieux.tamu.edu/?path=/story/components-cards-card-groups-card-slab--example-card-slab
 *
 * @author Jeremy Tarpley
 * @since 1.0.0
 */

use WP_AUX\Services\AuxCF\BlocksService;
use WP_AUX\Entities\AuxFramework\Partials\CardEntity;

$cardsType = aux_get_field('card_slab_cards_type');
$cardCtaType = aux_get_field('card_slab_cta_type');
$cards = aux_get_field('card_slab_card');

$cardsContent = '';
foreach ($cards as $card) {
  $cardEntity = CardEntity::create($card['card_heading'], $card['card_content'])
    ->setSuperheader($card['card_superheader'])
    ->setSubheader($card['card_subheader'])
    ->setIcon($card['card_icon'])
    ->setImage($card['card_image'])
    ->setHasIntro(true)
    ->setCta($card['card_slab_cta_link'])
    ->setType('featured-cards' === $cardsType ? 'standard' : 'linked')
    ->setCtaType('featured-cards' === $cardsType ? $cardCtaType : 'link')
    ->setIsFeature('featured-cards' === $cardsType);

  $cardsContent .= $cardEntity;
}

$slab = BlocksService::getSlab('card-slab');
$slab->setContent($cardsContent);

echo $slab;
