<?php
if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly

$settings = $args;

if( !empty($settings['recent_posts']) ) {
	?>
	<div class="popup-search-recent-posts-wrap">
		<?php if($settings['recent_posts_title']): ?>
			<h5 class="title"><?php echo esc_html($settings['recent_posts_title']); ?></h5>
		<?php endif; ?>
		<div class="popup-search-recent-posts">
			<?php
			$query_args = ['posts_per_page' => 3];
			$the_query = new WP_Query( $query_args );

			if ( $the_query->have_posts() ) {
				while ( $the_query->have_posts() ) {
					$the_query->the_post();
                    ?>
                     <div class="post-wrapper">
	                     <?php
                         if(has_post_thumbnail()) {
                             echo '<a href="' . esc_url(get_permalink()) . '" title="' . esc_attr(get_the_title()) . '">';
	                         $thumb_args = [ 'title' => get_the_title() ];
	                         the_post_thumbnail('thumbnail', $thumb_args);
                             echo '</a>';
                         }
	                     ?>
                         <div class="content-wrapper">
                             <h6><a class="title-animation-underline" href="<?php echo esc_url(get_permalink()); ?>" title="<?php echo esc_attr(get_the_title()); ?>"><?php echo esc_html( get_the_title() ); ?></a></h6>
                            <span class="date"><?php echo get_the_date() ?></span>
                         </div>
                     </div>
					<?php
				}
			}
			wp_reset_postdata();
			?>
		</div>
	</div>
	<?php
}
