<?php
/**
 * Frontend output for the AUX Link Slab component
 * AUX documentation: https://aggieux.tamu.edu/?path=/docs/components-link-slab-about-link-slabs--docs
 *
 * Outline:
 * 1. Set variables to null
 * 2. Get fields from the post, if they have values, wrap in html
 * 3. Build the component html
 * 4. Sanitize and output
 *
 * @author Hailey Sanders
 * @since 1.0.0
 */

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

$slab = BlocksService::getSlab('link-slab');
$slab->setWrapHeading(true);

// Create link list from user input
$linkListItems = aux_get_field('link_slab_link_list');
if ($linkListItems) {
  $linkList = LinkListEntity::create();
  $linkList->setColumns(aux_get_field('link_slab_columns'));

  foreach ($linkListItems as $linkItem) {
    $linkListItem = $linkList->addLink($linkItem['link_slab_link']);
  }
}

$slab->setContent(<<<HTML
  <div class="link-slab__links">
    $linkList
  </div>
HTML);

echo $slab;
