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

namespace MadeByAura\Prime;

use MadeByAura\Prime\Helpers\Markup;
use MadeByAura\Prime\Modules\Entries;

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

// Merge incoming `$args` with defaults.
$args = array_replace_recursive(
	[
		'layout'     => Entries::get_layout(),
		'pagination' => true,
	],
	$args,
);

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

// Set CSS classes.
$classes   = [];
$classes[] = 'aura-entries';
$classes[] = 'aura-entries--' . $args['layout'];
?>

<?php if ( have_posts() ) : ?>

	<div class="<?php Markup::echo_classes( $classes ); ?>">
		<?php while ( have_posts() ) : ?>
			<?php the_post(); ?>
			<?php Base::view( 'views/entry-layouts/' . $args['layout'] ); ?>
		<?php endwhile; ?>
	</div>

	<?php if ( true === $args['pagination'] ) : ?>
		<?php Base::view( 'views/pagination' ); ?>
	<?php endif; ?>

<?php else : ?>

	<?php Base::view( 'views/nothing-found' ); ?>

	<?php
endif;
