<?php
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
$searchValue = ($searchPlugin && $WHERE_AM_I === 'search') ? $searchPlugin->getSearchTerm() : '';
$searchMinChars = $searchPlugin ? max(1, (int) $searchPlugin->getValue('minChars')) : 1;
$searchAction = json_encode(Theme::siteUrl() . 'search/');
$socialIconMap = array(
	'github' => 'github',
	'gitlab' => 'gitlab',
	'twitter' => 'twitter-x',
	'facebook' => 'facebook',
	'instagram' => 'instagram',
	'codepen' => 'codepen',
	'linkedin' => 'linkedin',
	'telegram' => 'telegram',
	'youtube' => 'youtube',
	'dribbble' => 'dribbble'
);
?>

<nav class="navbar navbar-expand-lg neon-navbar" aria-label="<?php echo htmlspecialchars($L->get('Main navigation'), ENT_QUOTES, 'UTF-8'); ?>">
	<div class="container">
		<a class="navbar-brand" href="<?php echo Theme::siteUrl(); ?>">
			<span class="brand-signal" aria-hidden="true"></span>
			<span><?php echo htmlspecialchars($site->title(), ENT_QUOTES, 'UTF-8'); ?></span>
		</a>

		<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#darkNeonNavbar" aria-controls="darkNeonNavbar" aria-expanded="false" aria-label="<?php echo htmlspecialchars($L->get('Toggle navigation'), ENT_QUOTES, 'UTF-8'); ?>">
			<i class="bi bi-list" aria-hidden="true"></i>
		</button>

		<div class="collapse navbar-collapse" id="darkNeonNavbar">
			<ul class="navbar-nav ml-auto">
				<?php if ($site->homepage()) : ?>
					<li class="nav-item">
						<a class="nav-link<?php echo ($WHERE_AM_I === 'blog') ? ' active' : ''; ?>" href="<?php echo DOMAIN_BASE . ltrim($url->filters('blog'), '/'); ?>"><?php echo $L->get('Blog'); ?></a>
					</li>
				<?php endif; ?>

				<?php foreach ($staticContent as $staticPage) : ?>
					<li class="nav-item">
						<a class="nav-link<?php echo ($url->slug() == $staticPage->slug()) ? ' active' : ''; ?>" href="<?php echo $staticPage->permalink(); ?>"><?php echo htmlspecialchars($staticPage->title(), ENT_QUOTES, 'UTF-8'); ?></a>
					</li>
				<?php endforeach; ?>

				<?php foreach (Theme::socialNetworks() as $key => $label) : ?>
					<?php $icon = isset($socialIconMap[$key]) ? $socialIconMap[$key] : 'link-45deg'; ?>
					<li class="nav-item">
						<a class="nav-link nav-icon-link" 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>
							<span class="d-lg-none"><?php echo htmlspecialchars($label, ENT_QUOTES, 'UTF-8'); ?></span>
						</a>
					</li>
				<?php endforeach; ?>
			</ul>

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

<?php if ($searchPlugin) : ?>
<script>
function darkNeonSearch(inputId) {
	var input = document.getElementById(inputId);
	if (!input) return false;
	var value = input.value.trim();
	if (value.length < <?php echo $searchMinChars; ?>) return false;
	window.location.href = <?php echo $searchAction; ?> + encodeURIComponent(value);
	return false;
}
</script>
<?php endif; ?>
