<?php get_header(); ?>

<?php
$postId = get_the_ID(); 
$title = get_the_title(); 
$post = BlogModel::mountPosts([ 'limit' => 1, 'id' => $postId ])[0];
$tags = BlogModel::getTagsByPostId($postId);
?>



<!--==================================================-->
<!-- Start Breadcumb Area -->
<!--==================================================-->
<?php get_template_part('template-parts/section', 'breadcrumbs', [
  'title' => $title,
  'image' => $post['srcFull'],//getTheme('assets/neoplan/dealership-banner.jpg'),
  'multiplyBlendingEffect' => true,
  'breadcrumbs' => [
    [
      'title' => 'Início',
      'href' => '/'
    ],
		[
      'title' => 'Blog',
      'href' => getBaseUrl('blog')
    ],
    [
      'title' => $title,
    ],
  ]
]); ?>
<!--==================================================-->
<!-- End Breadcumb Area -->
<!--==================================================-->

<!--==================================================-->
<!-- Start Service Details Area -->
<!--==================================================-->
<section class="blog-single-post portfolio_details">
	<div class="container">
		<div class="port_main style_two">
		
			<div class="row">
				<?php 
					echo $post['content'];
				?>
			</div>

			<div class="row">
				<div class="col-lg-12">
					<div class="pagination_container style_two">

						<!-- Categorias -->
						<ul class="blog-category d-flex flex-wrap gap-2">
							<h5 class="mb-4">Categorias:</h5>
							<?php foreach ($post['categories']  as $category) { ?>
							<li><a href="/blog/categoria/<?php echo $category['slug']; ?>"><?php echo $category['name']; ?></a></li>
							<?php } ?>
						</ul>						
						<!-- pagination item -->
						<!-- <div class="pagination_item">
							<div class="call_social_icon">
								<ul>
									<li><a href="#"><i class="fab fa-linkedin-in"></i></a></li>
									<li><a href="#"><i class="fab fa-pinterest-p"></i></a></li>
									<li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
									<li><a class="top-social-icon-left" href="#"><i class="fab fa-twitter"></i></a></li>
								</ul>
							</div>
						</div> -->
					</div>

					<?php if (!empty($post['tags'])) { ?> 
					<div class="box-invisible" style="border-top: 2px solid black;"></div>
					<!-- Tags -->
					<ul class="blog-category d-flex flex-wrap gap-2">
						<h5 class="mb-4">Tags:</h5>
						<?php foreach ($post['tags'] as $tag) { ?>
						<li><a href="/blog/tag/<?php echo $tag['slug']; ?>"><?php echo $tag['name']; ?></a></li>
						<?php } ?>
					</ul>						
					<?php } ?>
						
					<?php 
						// $prevPost = get_previous_post_link();
						// $nextPost = get_next_post_link();
						// var_dump([
						// 	'$prevPost' => $prevPost,
						// 	'$nextPost' => $nextPost
						// ]);
					/* 
					?>
					<div class="pagination_container">
						<!-- pagination item -->
						<div class="pagination_item">
							<div class="pagination_btn">
								<a href="javascript:void();"><img src="<?php echo getTheme('assets/images/inner-img/pagination_icon1.png'); ?>" alt="">Notícia Anterior</a>
							</div>
						</div>						

						<!-- pagination item -->
						<div class="pagination_item">
							<div class="pagination_btn style_right">
								<a href="javascript:void();">Notícia Posterior <img src="<?php echo getTheme('assets/images/inner-img/pagination_icon2.png'); ?>" alt=""></a>
							</div>
						</div>

					</div>
					<?php */ ?>
				</div>
			</div>

			<!-- Comentários na notícia -->
			<?php /* ?>
			<div class="row">
				<div class="col-lg-12">
					<div class="blog-details-contents">
						<h3><?php echo CommentView::totalCount($postId); ?> Comentários</h3>	
					</div>

					<?php 
						$comments = CommentView::getComments([
							'post_id' => $postId,
							'status' => 'approve'
						]); 

						foreach ($comments as $comment) {
							get_template_part('template-parts/blog', 'comment', $comment); 
						} 
					?>

					<a href="javascript:void();" class="d-block text-end mt-5" id="loading-comments">Ver Mais</a>
				</div>
			</div>
			<div class="row">
				<div class="col-lg-12">
					<?php get_template_part('template-parts/form', 'comment', []); ?>
				</div>
			</div>
			<?php */ ?>

		</div>
	</div>
</section>
<!--==================================================-->
<!-- End Service Details Area -->
<!--==================================================-->

<!--==================================================-->
<!-- Start Blog Area -->
<!--==================================================-->
<section class="blog_area inner_page two">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<div class="section_title text-center">
					<h1>Notícias Relacionadas</h1>
				</div>
			</div>		
		</div>
		<div class="row">
			<?php 
				// Carregar os 3 posts recentes relacionados a categorias dessa postagem 
				echo BlogView::showBlogItems([
					'limit' => 3,
					'categories' => array_column(BlogModel::getCategoriesByPostId($postId), 'name'),
					'excludePostsId' => [$postId]
				]);
			?>
		</div>
	</div>
</section>
<!--==================================================-->
<!-- End Blog Area -->
<!--==================================================-->

<!--==================================================-->
<!-- Start Section Information Strip -->
<!--==================================================-->
<?php /* get_template_part('template-parts/section', 'information-strip', []); */?>
<!--==================================================-->
<!-- End Section Information Strip -->
<!--==================================================-->

<script type="text/javascript">
  $$page = "detalhes-noticia";
</script>

<?php get_footer(); ?>