<?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'      => 4,
			'post_status'         => 'publish',
			'ignore_sticky_posts' => true,
			'post__not_in'        => ! empty( $popular_posts )
				? [ $popular_posts[0]->ID ]
				: [],
		]
	);

?>
<section class="g-30c48c40" data-mui-dimension="74d2fb4dd0" data-block-animation="bounce" data-bs-locator="f46360c4c">
	<div class="g-63e2c1ff" id="elem-abbb4b5fb9148f33">
		<div class="g-17f34e5a" data-widget-mode="edit" data-element-position="left">
			<?php if ( ! empty( $popular_posts ) ) : ?>
				<div
					class="g-9eec51e9"
					aria-labelledby="popular-post-title"
				>
					<div class="g-2e4868b1" id="elem-438d524260fc9a4b">
						<h2
							id="popular-post-title"
							class="g-c0f4298f g-4d7b4f87"
							data-bs-color="success" data-element-state="loading"
						>
							Popular posts
						</h2>
					</div>
					<div class="g-731218b5 g-8dd0b5fd" id="elem-2583dfc7af4bf12d">
						<?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-c2072ca3"
					aria-labelledby="latest-posts-title"
				>
					<div class="g-2b4a65d4" data-component-action="hover" data-module-variant="filled" data-mui-disabled="86d4b3111" data-component-group="3ad8e33ac5">
						<h2
							id="latest-posts-title"
							class="g-c0f4298f g-4d7b4f87"
							id="elem-bfc3efb4b6d47e1e"
						>
						Latest posts
						</h2>
					</div>
					<div class="g-e82fdaa1 g-8dd0b5fd" data-section-priority="high" data-module-status="archived">
						<?php
							foreach ( $latest_posts as $post ) :
								setup_postdata( $post );
								?>
								<?php
								get_template_part(
									'templates/post-card',
									null,
									[
										'size' => 'small',
									]
								);
								?>
							<?php
							endforeach;
							wp_reset_postdata();
						?>
					</div>
				</aside>
			<?php endif; ?>
		</div>
		<?php
			$posts_page_id = get_option( 'page_for_posts' );

			if ( $posts_page_id ) :
				?>
				<div class="g-e4256585" data-analytics-mock="9bfab503f" data-analytics-automation="1ed41cc7d125" data-mui-color="primary" data-block-action="click">
					<a href="<?php echo esc_url( get_permalink( $posts_page_id ) ); ?>" class="g-1efedfb7" id="elem-0d530b2a29e8c496">
						<span>View all</span>
					</a>
				</div>
			<?php endif; ?>
	</div>
</section>