{%- from 'macro.html' import nav_item -%}
{%- set next_url = (url_for(request.endpoint, **request.view_args) if request.endpoint and not request.endpoint.startswith('auth.') and request.view_args != None else None) -%}

<div id="mobile-menu-btn" class="nav-icon mobile-menu-btn"></div>

<div id="nav-main-profile" class="nav-main-profile">
{%- if current_user.is_authenticated %}
    <div class="nav-icon nav-icon-bell">
        <a id="nav-icon-bell" class="nav-icon-bell-link" href="{{ url_for('notifications.index') }}" data-ajax="{{ url_for('notifications.index', popup='1') }}"  title="{{ _('Notifications') }}"></a>
        {% set notifications_count = get_unread_notifications_count() %}
        <span class="new-count js-notifications-count"{% if notifications_count < 1 %} style="display: none"{% endif %}>{{ notifications_count }}</span>
        <div class="bell-popup" id="bell-popup" style="display: none;">
            <div class="bell-popup-content" id="bell-popup-content">test</div>
        </div>
    </div>
    <a href="{{ url_for('story.add') }}" class="nav-icon nav-icon-add{% if is_current_endpoint('story.add') %} active{% endif %}" title="{{ _('Add story') }}"></a>
    <div class="nav-profile-menu">
    <div class="nav-profile-menu-header" id="nav-profile-menu-header">
        <div class="nav-profile-menu-text"><span class="nav-username">{{ current_user.username }}</span></div><img src="{{ current_user.bl.get_avatar_url() }}" alt="" class="nav-user-avatar" />
    </div>
    <ul class="nav-profile-menu-content nav-items" id="nav-profile-menu-content">
        {{ nav_item(
            _('Favorites'),
            url_for('object_lists.favorites', user_id=current_user.id),
            matched=is_current_endpoint('object_lists.favorites', user_id=current_user.id)
        ) }}
        {{ nav_item(_('Read later'), url_for('object_lists.bookmarks'), 'object_lists.bookmarks') }}
        {{ nav_item(
            _('Settings'),
            url_for('author.edit'),
            matched=is_current_endpoint('author.edit'),
        ) }}
        {{ nav_item(
            _('My profile'),
            url_for('author.info', user_id=current_user.id),
            matched=is_current_endpoint('author.info', user_id=current_user.id),
        ) }}
        {{ nav_item(
            _("Author's cabinet"),
            url_for('author.info'),
            matched=is_current_endpoint('author.info', user_id=None),
        ) }}
        {% if current_user.is_staff %}
            {{ nav_item(
                _('Administration'),
                url_for('admin_index.index'),
                'admin_index.index',
            ) }}
        {% endif %}
        {{ nav_item(_('Log out'), url_for('auth.logout', next=next_url), noajax=True) }}
    </ul>
    </div><!-- /nav-profile-menu -->
{%- else -%}
<ul class="nav-items">
    {{ nav_item(_('Log in'), url_for('auth.login', next=next_url), 'auth.login') }}
    {%- if config.REGISTRATION_OPEN %}
        {{ nav_item(_('Register'), url_for('auth.registration'), 'auth.registration') }}
    {% endif %}
</ul>
{%- endif -%}
</div><!-- /nav-main-profile -->

<ul id="nav-main-links" class="nav-items nav-main-links">
    {{ nav_item(_('Index'), url_for('index.index'), 'index.index') }}
    {{ nav_item(_('Search'), url_for('search.main'), 'search.') }}
    {% if current_user.is_staff %}
        {{ nav_item(
            'Новые ({})'.format(submitted_stories_count()),
            url_for('object_lists.submitted'),
            match_endpoint='object_lists.submitted'
        ) }}
    {% endif %}
    {{ nav_item(
        'Справка',
        url_for('staticpages.index', name='help'),
        matched=is_current_endpoint('staticpages.index', name='help')
    ) }}
    {{ hook('nav') }}
</ul>
