<?php
/**
 * The template to display entry terms.
 *
 * This template can be overridden by copying it to
 * your-child-theme/views/entry/terms.php.
 *
 * @param array $args
 *
 * @package MadeByAura\Prime
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime;

use MadeByAura\Prime\Helpers\Markup;

defined( 'ABSPATH' ) || die();

// Merge incoming `$args` with defaults.
$args = array_replace_recursive(
	[
		'type'      => 'categories',
		'taxonomy'  => 'category',
		'title'     => '',
		'separator' => ', ',
		'class'     => '',
	],
	$args,
);

// Do not proceed if there is no taxonomy.
if ( ! $args['taxonomy'] ) {
	return;
}

// Get terms.
$terms = get_the_term_list( null, $args['taxonomy'], '', $args['separator'], '' );

// Do not proceed if there are no terms.
if ( ! $terms ) {
	return;
}

// Set CSS classes.
$classes[] = $args['class'];
$classes[] = 'aura-entry-terms';
$classes[] = $args['type'] ? 'aura-entry-terms--' . $args['type'] : '';
?>

<div class="<?php Markup::echo_classes( $classes ); ?>">
	<?php if ( $args['title'] ) : ?>
		<span><?php echo esc_html( $args['title'] ); ?></span>
	<?php endif; ?>

	<?php echo wp_kses_post( $terms ); ?>
</div>
