<?php

if (!function_exists('flo_items_pagination_frontend')) {
	function flo_items_pagination_frontend($atts = [])
	{
		global $post;
		extract($atts);

		$next_item = get_next_post();
		$prev_item = get_previous_post();


		if ($prev_item) {
			$prev_url = get_the_permalink($prev_item->ID);
			$prev_title = get_the_title($prev_item->ID);
			$prev_categories = get_the_category($prev_item->ID);
			$prev_thumbnail_id = get_post_thumbnail_id($prev_item->ID);
			$prev_item_image_url = wp_get_attachment_image_url($prev_thumbnail_id, 'full');
			$prev_item_image_srcset =wp_get_attachment_image_srcset($prev_thumbnail_id, 'medium');
		}

		if ($next_item) {
			$next_url = get_the_permalink($next_item->ID);
			$next_title = get_the_title($next_item->ID);
			$next_categories = get_the_category($next_item->ID);
			$next_thumbnail_id = get_post_thumbnail_id($next_item->ID);
			$next_item_image_url = wp_get_attachment_image_url($next_thumbnail_id, 'full');
			$next_item_image_srcset =wp_get_attachment_image_srcset($next_thumbnail_id, 'medium');
		}

		$b= 'flo-block-item-pagination';
		ob_start();
		if ($prev_item || $next_item) {
			?>
				<div class="flo-block <?php echo $atts['className' ]; ?> <?php echo Flo_Guten_Blocks_Helper::get_additional_class($atts);
			echo $b; ?> alignfull <?php echo $enableSticky ? "pagination-sticky" : "" ?> " style="
										--top-margin: <?php echo Flo_Guten_Blocks_Helper::get_em_by_value($topMargin); ?>;
										--bottom-margin:<?php echo Flo_Guten_Blocks_Helper::get_em_by_value($bottomMargin); ?>;
										--mobile-top-margin: <?php echo Flo_Guten_Blocks_Helper::get_em_by_value($mobileTopMargin); ?>;
										--mobile-bottom-margin: <?php echo Flo_Guten_Blocks_Helper::get_em_by_value($mobileBottomMargin); ?>;
										--block-items-color: <?php echo Flo_Guten_Blocks_Helper::get_style_color($titleColor); ?> ;
										--block-background-color: <?php echo Flo_Guten_Blocks_Helper::get_style_color($BackgroundColor); ?> ;
										<?php echo Flo_Guten_Blocks_Helper::get_style_for_typography('pagination-item-title', $postTitleFont); ?>
										<?php echo Flo_Guten_Blocks_Helper::get_style_for_typography('pagination-item-label', $labelsFont); ?>
										<?php echo Flo_Guten_Blocks_Helper::get_style_for_typography('pagination-item-category', $postTaxonomyFont); ?>
					 ">
						<?php
						if ($layout === 'item-pagination-1') { ?>
							<div class="<?php echo $b;?>__wrap item-pagination-1">							
								<div class="<?php echo $b;?>__prev">
								<?php if ($prev_item) {?>
									
									<a href="<?php echo $prev_url;?>">
									<i class="gbp-icon-keyboard_arrow_down-24px"></i>	
									<span class="<?php echo $b;?>__label"
											data-font="<?php echo $labelsFont['type'] == 'theme' ? $labelsFont['theme'] : ''; ?>" >
										
											<?php echo $previousPostLabel;?>
											
										</span>
									
									</a>
									<?php }?>
								</div>
								<div class="<?php echo $b;?>__next">
								<?php if ($next_item) {?>
								<a href="<?php echo $next_url;?>">	
									<span class="<?php echo $b;?>__label"
										data-font="<?php echo $labelsFont['type'] == 'theme' ? $labelsFont['theme'] : ''; ?>" >
										<?php echo $nextPostLabel;?>
										
									</span>
									<i class="gbp-icon-keyboard_arrow_down-24px"></i>
								</a>
								<?php }?>
								</div>
							
							</div>
					<?php	} ?>
					<?php 	if ($layout === 'item-pagination-2') { ?>
						<div class="<?php echo $b;?>__wrap item-pagination-2">
					
								<div class="<?php echo $b;?>__prev">
								<?php if ($prev_item) { ?>
								<?php if ($displayPostImage) {?>
										<div class="<?php echo $b;?>__prev-image">
										<?php if ($prev_item_image_url) {?>
										<a class="image_link" href="<?php echo $prev_url;?>"><img class="<?php echo $b;?>__feat-image" src="<?php echo $prev_item_image_url; ?>" srcset="<?php echo $prev_item_image_srcset ? $prev_item_image_srcset : ''; ?>" /></a>
										<?php }?>
										</div>
									<?php } ?>
									<div class="<?php echo $b;?>__prev-text">
												<?php if ($displayPostTaxonomy && $prev_categories) {?>
													<span
													class="<?php echo $b;?>__category"
													data-font="<?php echo $postTaxonomyFont['type'] == 'theme' ? $postTaxonomyFont['theme'] : ''; ?>" >
														<?php echo $prev_categories[0]->name;?>
													</span>
												<?php } ?>
												<<?php echo !empty($titleTagName) ? $titleTagName : 'h2'; ?> class="<?php echo $b;?>__title-head">
												<a href="<?php echo $prev_url;?>">
												<i class=" gbp-icon-keyboard_arrow_down-24px"></i>	
												<span class="<?php echo $b;?>__title"
													data-font="<?php echo $postTitleFont['type'] == 'theme' ? $postTitleFont['theme'] : ''; ?>" >
													
													<?php echo $prev_title;?>
												
													</span>
												
												</a>	
												</<?php echo !empty($titleTagName) ? $titleTagName : 'h2'; ?>>
												<?php if ($displayLabels) {?>
													<a class ="label-link" href="<?php echo $prev_url;?>">
													<i class=" gbp-icon-keyboard_arrow_down-24px"></i>	
													<span class="<?php echo $b;?>__label"
													data-font="<?php echo $labelsFont['type'] == 'theme' ? $labelsFont['theme'] : ''; ?>" >
													<?php echo $previousPostLabel;?>
													
												</span>
												
													</a>
												<?php }?>
											</div>
											<?php } ?>
									</div>
						
						
									<div class="<?php echo $b;?>__next">
									<?php if ($next_item) { ?>
									<?php if ($displayPostImage) {?>
										<div class="<?php echo $b;?>__next-image">
										<?php if ($next_item_image_url) {?>
										<a class="image_link" href="<?php echo $next_url;?>"><img class="<?php echo $b;?>__feat-image" src="<?php echo $next_item_image_url; ?>" srcset="<?php echo $next_item_image_srcset ? $next_item_image_srcset : ''; ?>"/></a>
										<?php }?>
										</div>
									<?php } ?>
									<div class="<?php echo $b;?>__next-text">
										<?php if ($displayPostTaxonomy && $next_categories) {?>
												<span
												class="<?php echo $b;?>__category"
												data-font="<?php echo $postTaxonomyFont['type'] == 'theme' ? $postTaxonomyFont['theme'] : ''; ?>" >
													<?php echo $next_categories[0]->name;?>
												</span>
											<?php } ?>
											<<?php echo !empty($titleTagName) ? $titleTagName : 'h2'; ?> class="<?php echo $b;?>__title-head">
											<a href="<?php echo $next_url;?>">
											<span class="<?php echo $b;?>__title"
											data-font="<?php echo $postTitleFont['type'] == 'theme' ? $postTitleFont['theme'] : ''; ?>" >
												<?php echo $next_title;?>
											
											</span>
											<i class=" gbp-icon-keyboard_arrow_down-24px"></i>
											</a>
											</<?php echo !empty($titleTagName) ? $titleTagName : 'h2'; ?>>
											<?php if ($displayLabels) {?>
												<a class ="label-link" href="<?php echo $next_url;?>">
												<span class="<?php echo $b;?>__label"
												data-font="<?php echo $labelsFont['type'] == 'theme' ? $labelsFont['theme'] : ''; ?>" >
												<?php echo $nextPostLabel;?>
												
											</span>
											<i class=" gbp-icon-keyboard_arrow_down-24px"></i>	
												</a>
											<?php }?>
										</div>
										<?php }?>		
									</div>
							
						</div>

				<?php } ?>


	
				</div>
	<?php
		}
		$info = ob_get_clean();
		return $info;
	}
}
