<?php
/**
 * AUX Media Slab template
 */

use WP_AUX\Entities\AuxFramework\Partials\CaptionedMediaEntity;
use WP_AUX\Services\HtmlService;

$captionedMedia = '';

// grab media type
$mediaType = aux_get_field('captioned_media_type');

if (!$mediaType) {
  return;
}

$media = aux_get_field_array($mediaType);

if ($media) {
  // Create captioned media partial, setting the file, heading, and credit from user input
  $captionedMedia = CaptionedMediaEntity::create(
    $media,
    $mediaType,
    aux_get_field('captioned_media_caption'),
    aux_get_field('captioned_media_credit')
  )
    ->setAlign(aux_get_field('captioned_media_display'));
}

// Render captioned media partial
echo $captionedMedia;
