<?php
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
$sidebarHtml = '';
ob_start();
Theme::plugins('siteSidebar');
$sidebarHtml = trim(ob_get_clean());
$socialNetworks = Theme::socialNetworks();
$socialIconMap = array(
	'github' => 'github',
	'gitlab' => 'gitlab',
	'twitter' => 'twitter-x',
	'facebook' => 'facebook',
	'instagram' => 'instagram',
	'codepen' => 'codepen',
	'linkedin' => 'linkedin',
	'telegram' => 'telegram',
	'youtube' => 'youtube',
	'dribbble' => 'dribbble'
);
?>

<?php if ($WHERE_AM_I !== 'search') : ?>
<section class="neon-hero">
	<div class="container">
		<div class="hero-panel">
			<div class="accent-strip" aria-hidden="true">
				<span></span><span></span><span></span><span></span><span></span>
			</div>
			<div class="hero-copy">
				<p class="hero-kicker"><?php echo htmlspecialchars($site->title(), ENT_QUOTES, 'UTF-8'); ?></p>
				<h1><?php echo htmlspecialchars($site->slogan() ? $site->slogan() : $site->title(), ENT_QUOTES, 'UTF-8'); ?></h1>
				<?php if ($site->description()) : ?>
					<p><?php echo htmlspecialchars($site->description(), ENT_QUOTES, 'UTF-8'); ?></p>
				<?php endif; ?>
			</div>

			<?php if ($searchPlugin) : ?>
				<form class="hero-search" role="search" onsubmit="return darkNeonSearch('dark-neon-hero-search');">
					<label class="sr-only" for="dark-neon-hero-search"><?php echo $L->get('Search'); ?></label>
					<i class="bi bi-search" aria-hidden="true"></i>
					<input id="dark-neon-hero-search" type="search" placeholder="<?php echo htmlspecialchars($L->get('Search'), ENT_QUOTES, 'UTF-8'); ?>" autocomplete="off">
					<button type="submit"><i class="bi bi-arrow-right" aria-hidden="true"></i><span><?php echo $L->get('Search'); ?></span></button>
				</form>
			<?php endif; ?>
		</div>
	</div>
</section>
<?php endif; ?>

<section class="content-band">
	<div class="container">
		<div class="row">
			<div class="<?php echo (!empty($sidebarHtml) || !empty($socialNetworks)) ? 'col-lg-8' : 'col-lg-9 mx-auto'; ?>">
				<?php if (empty($content)) : ?>
					<div class="empty-state">
						<i class="bi bi-stars" aria-hidden="true"></i>
						<h2><?php $language->p('No pages found'); ?></h2>
					</div>
				<?php endif; ?>

				<div class="post-list">
					<?php foreach ($content as $page) : ?>
						<article class="neon-post">
							<?php Theme::plugins('pageBegin'); ?>

							<?php if ($page->coverImage()) : ?>
								<a class="post-cover" href="<?php echo $page->permalink(); ?>" aria-label="<?php echo htmlspecialchars($page->title(), ENT_QUOTES, 'UTF-8'); ?>">
									<img src="<?php echo $page->coverImage(); ?>" alt="<?php echo htmlspecialchars($page->title(), ENT_QUOTES, 'UTF-8'); ?>" loading="lazy">
								</a>
							<?php endif; ?>

							<div class="post-body">
								<div class="post-meta">
									<span><i class="bi bi-calendar3" aria-hidden="true"></i><?php echo $page->date(); ?></span>
									<span><i class="bi bi-stopwatch" aria-hidden="true"></i><?php echo $page->readingTime(); ?></span>
									<?php if ($page->categoryKey()) : ?>
										<a href="<?php echo $page->categoryPermalink(); ?>"><i class="bi bi-folder2-open" aria-hidden="true"></i><?php echo htmlspecialchars($page->category(), ENT_QUOTES, 'UTF-8'); ?></a>
									<?php endif; ?>
								</div>

								<h2 class="post-title">
									<a href="<?php echo $page->permalink(); ?>"><?php echo htmlspecialchars($page->title(), ENT_QUOTES, 'UTF-8'); ?></a>
								</h2>

								<?php if ($page->description() && $WHERE_AM_I !== 'search') : ?>
									<p class="post-description"><?php echo htmlspecialchars($page->description(), ENT_QUOTES, 'UTF-8'); ?></p>
								<?php endif; ?>

								<div class="post-excerpt">
									<?php echo $page->contentBreak(); ?>
								</div>

								<?php $tagsList = $page->tags(true); ?>
								<?php if (!empty($tagsList)) : ?>
									<div class="taxonomy-list">
										<?php foreach ($tagsList as $tagKey => $tagName) : ?>
											<a href="<?php echo DOMAIN_TAGS . $tagKey; ?>"><i class="bi bi-tag" aria-hidden="true"></i><?php echo htmlspecialchars($tagName, ENT_QUOTES, 'UTF-8'); ?></a>
										<?php endforeach; ?>
									</div>
								<?php endif; ?>

								<?php if ($page->readMore() || $WHERE_AM_I === 'search') : ?>
									<a class="read-link" href="<?php echo $page->permalink(); ?>">
										<span><?php echo ($WHERE_AM_I === 'search') ? $L->get('Open result') : $L->get('Read more'); ?></span>
										<i class="bi bi-arrow-right" aria-hidden="true"></i>
									</a>
								<?php endif; ?>
							</div>

							<?php Theme::plugins('pageEnd'); ?>
						</article>
					<?php endforeach; ?>
				</div>

				<?php if (Paginator::numberOfPages() > 1) : ?>
					<nav class="neon-pagination" aria-label="<?php echo htmlspecialchars($L->get('Page navigation'), ENT_QUOTES, 'UTF-8'); ?>">
						<?php if (Paginator::showPrev()) : ?>
							<a href="<?php echo htmlspecialchars(Paginator::previousPageUrl(), ENT_QUOTES, 'UTF-8'); ?>"><i class="bi bi-chevron-left" aria-hidden="true"></i><?php echo $L->get('Previous'); ?></a>
						<?php endif; ?>
						<a href="<?php echo Theme::siteUrl(); ?>"><i class="bi bi-house" aria-hidden="true"></i><?php echo $L->get('Home'); ?></a>
						<?php if (Paginator::showNext()) : ?>
							<a href="<?php echo htmlspecialchars(Paginator::nextPageUrl(), ENT_QUOTES, 'UTF-8'); ?>"><?php echo $L->get('Next'); ?><i class="bi bi-chevron-right" aria-hidden="true"></i></a>
						<?php endif; ?>
					</nav>
				<?php endif; ?>
			</div>

			<?php if (!empty($sidebarHtml) || !empty($socialNetworks)) : ?>
				<aside class="col-lg-4">
					<div class="neon-sidebar">
						<?php echo $sidebarHtml; ?>

						<?php if (!empty($socialNetworks)) : ?>
							<div class="plugin social-panel">
								<h2 class="plugin-label"><?php echo $L->get('Connect'); ?></h2>
								<div class="plugin-content social-links">
									<?php foreach ($socialNetworks as $key => $label) : ?>
										<?php $icon = isset($socialIconMap[$key]) ? $socialIconMap[$key] : 'link-45deg'; ?>
										<a href="<?php echo htmlspecialchars($site->{$key}(), ENT_QUOTES, 'UTF-8'); ?>" target="_blank" rel="noopener" aria-label="<?php echo htmlspecialchars($label, ENT_QUOTES, 'UTF-8'); ?>">
											<i class="bi bi-<?php echo $icon; ?>" aria-hidden="true"></i>
										</a>
									<?php endforeach; ?>
								</div>
							</div>
						<?php endif; ?>
					</div>
				</aside>
			<?php endif; ?>
		</div>
	</div>
</section>
