<?php
/**
 * Frontend output for the AUX Footer Column - Link List block
 * This is only to be used for footers and should not be brought in to the main page builder
 *
 * AUX documentation: https://aggieux.tamu.edu/?path=/docs/navigation-footers-footer-option-a-about-footer-option-a--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\HtmlService;
use WP_AUX\Entities\AuxFramework\Partials\LinkListEntity;

// Set variables to null
$footerColumnHeading =
$footerColumnLinkList = null;

// Get fields from the post, if they have values, wrap in html
$footerColumnHeading = aux_get_field('footer_column_heading');
$footerColumnLinkListItems = get_field('footer_column_link_list');

$footerColumnHeading = HtmlService::formattedValue($footerColumnHeading, '<span class="column__header">%s</span> ');

// Creating the link list
$footerColumnLinkList = LinkListEntity::create();

if (!empty($footerColumnLinkListItems)) {
  // Loop through link items to add to link list
  foreach ($footerColumnLinkListItems as $linkItem) {
    $footerColumnLinkList->addLink($linkItem['footer_column_link_list_link']);
  }
}

// Build the component HTML
$output = <<<HTML
<div class="footer__column">
  $footerColumnHeading
  $footerColumnLinkList
</div>
HTML;

// Sanitize and output
echo $output;
