{% set user = app.getUser() %}

<div class="navbar navbar-expand-lg navbar-light bg-light">
	<div class="container">
		<a class="navbar-brand" href="{{ doc_url('/') }}">Pimweb</a>
		<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>

		<div class="collapse navbar-collapse" id="navbarSupportedContent">
			<ul class="navbar-nav mr-auto">
				{% set mainNavCache = pimcore_cache(mainNavCacheKey) %}
				{% if not isFrontendRequestByAdmin and not mainNavCache.start() %}

					{% set mainNav = get_main_navigation(rootDocument) %}
					{% for item in mainNav %}
						<li{% if doc_is_active(item.getId()) %} {{ ' class="active"' }} {% endif %}>
							<a class="nav-link" title="{{ item.getProperty('navigation_name') }}" target="_self" href="{{ doc_url(item.getRealFullpath()) }}">
								{{ item.getProperty('navigation_name') }}
							</a>
						</li>
					{% endfor %}

					{% do mainNavCache.end() %}
				{% endif %}
			</ul>
			<ul class="nav navbar-nav navbar-right">
				{# Default language switch markup #}
				<li class="dropdown">
					<a class="nav-link dropdown-toggle sh-trig" data-content="dropdown" href="#">Jazyk<b class="caret"></b></a>

					{% set lngSwitchCache = pimcore_cache(languageSwitchCacheKey) %}
					{% if not isFrontendRequestByAdmin and not lngSwitchCache.start() %}
						{% if languageSwitch.pages is empty and document is instanceof('\\Pimcore\\Model\\Document\\Page') %}
							{% set switchPages = get_language_switch(language, document.getRealFullPath()) %}
						{% else %}
							{% set switchPages = languageSwitch.pages %}
						{% endif %}

						{% if switchPages is not empty %}
							<ul class="dropdown-menu" id="dropdown">
								{% for switchLanguage, path in switchPages %}
									<li{% if languageSwitch == language %}{{ ' class="active"' }}{% endif %}>
										<a href="{{ path }}">{{ switchLanguage }}</a>
									</li>
									{# $iconFile = \Pimcore\Tool::getLanguageFlagFile($language);
									$iconUrl = preg_replace("@^" . preg_quote(PIMCORE_WEB_ROOT, "@") . "@", "", $iconFile);
									echo sprintf('<li%s><a href="%s"><img src="%s" height="15"> %s</a></li>',
										(($language == $this->language) ? ' class="active"' : ''),
										$path,
										$iconUrl,
										$language
									); #}
								{% endfor %}
							</ul>
						{% endif %}

						{% do lngSwitchCache.end() %}
					{% endif %}
				</li>

				{# User menu #}
				{% if user is defined and user %}
					<li class="nav-item dropdown">
						<a class="nav-link dropdown-toggle sh-trig" role="button" data-content="user-dropdown" aria-haspopup="true" aria-expanded="false" href="#">{{ user.getUsername() }}<b class="caret"></b></a>
						<ul class="dropdown-menu" id="user-dropdown">
							<li><a class="dropdown-item" href="{{ doc_url('/ucet/profil') }}" target="_self">Profil</a></li>
							<li><a class="dropdown-item" href="{{ doc_url('/ucet/zmena-hesla') }}" target="_self">Změna hesla</a></li>
							<li class="divider"></li>
							<li><a class="dropdown-item" href="/logout" target="_self">Odhlásit</a></li>
						</ul>
					</li>
				{% else %}
					<li><a class="nav-link" href="{{ doc_url('/prihlaseni') ~ ((backlink is defined and backlink) ? ('?backlink=' ~ backlink) : '') }}" target="_self">Přihlášení</a></li>
				{% endif %}
			</ul>
		</div>
	</div>
</div>