<?php

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}
	/**
	 * Popular post
	 */
	$popular_posts = get_posts(
		[
			'post_type'           => 'post',
			'posts_per_page'      => 1,
			'meta_key'            => 'is_popular',
			'meta_value'          => '1',
			'ignore_sticky_posts' => true,
		]
	);
	/**
	 * Latest posts
	 */
	$latest_posts = get_posts(
		[
			'post_type'           => 'post',
			'posts_per_page'      => 3,
			'post_status'         => 'publish',
			'ignore_sticky_posts' => true,
			'post__not_in'        => ! empty( $popular_posts )
				? [ $popular_posts[0]->ID ]
				: [],
		]
	);

?>
<section class="g-488e09c1" data-module-status="published" data-mui-component="744c08" data-mui-target="920bc44f1a30" data-element-type="link">
	<div class="g-b24e2866" id="elem-fc8b2e4f978aeb40">
		<div class="g-cb4301d2" data-module-type="button" data-test-dismiss="66d96438">
			<?php if ( ! empty( $popular_posts ) ) : ?>
				<div
					class="g-294aa9b6"
					aria-labelledby="popular-post-title"
				>
					<div class="g-9f0c4d05" id="elem-345029d5d9de30b3">
						<h2
							id="popular-post-title"
							class="g-c0075e6e g-5e158376"
							data-bs-variant="contained" data-section-mode="edit" data-mui-toggle="collapse"
						>
						Popular posts
						</h2>
					</div>
					<div class="g-6b9d3eab g-a7fcd570" id="elem-c865137d96d61cce">
						<?php
							$post = $popular_posts[0];
							setup_postdata( $post );
							get_template_part(
								'templates/post-card',
								null,

							);
							wp_reset_postdata();
						?>
					</div>
				</div>
			<?php endif; ?>
			<?php if ( ! empty( $latest_posts ) ) : ?>
				<aside
					class="g-fc211b7f"
					aria-labelledby="latest-posts-title"
				>
					<div class="g-a2c2b382 g-c43ecf6f" data-bs-qa="66d813da8" data-test-ride="298e29da31c">
						<h2
							id="latest-posts-title"
							class="g-c0075e6e g-278f1f3e"
							id="elem-ca80f7216cbdceb5"
						>
						Latest posts
						</h2>
					</div>
					<?php
						foreach ( $latest_posts as $key => $post ) :
							setup_postdata( $post );
							?>
							<?php
							if ( $key !== 0 ) {
								echo '<hr class="g-80f0d6e0" />';
							}
							get_template_part(
								'templates/post-card',
								null,
								[
									'size' => 'small',
								]
							);
							?>
						<?php
						endforeach;
						wp_reset_postdata();
					?>
				</aside>
			<?php endif; ?>
		</div>
		<?php
			$posts_page_id = get_option( 'page_for_posts' );

			if ( $posts_page_id ) :
				?>
				<div class="g-c3d70c25" data-mui-interval="2ee521e772d" data-analytics-dimension="d8422a">
					<a href="<?php echo esc_url( get_permalink( $posts_page_id ) ); ?>" class="g-e5f3f08c" id="elem-b1a92f87e2eb72f3">
						<span>View all</span>
					</a>
				</div>
			<?php endif; ?>
	</div>
</section>