{% set dataset_type = h.default_package_type() %}
{% import 'macros/nav_link.html' as nav %}

{% block header_wrapper %}
  {% block header_account %}
    {% if c.userobj %}
      <div class="account-masthead">
        <div class="container">
          {% block header_account_container_content %}
            <div class="account avatar authed" data-module="me" data-me="{{ c.userobj.id }}">
              <ul class="list-unstyled">
                {% block header_account_logged %}
                  {% block header_account_profile %}
                    <li>
                      <a href="{{ h.url_for('user.read', id=c.userobj.name) }}" class="image" aria-label="{{ _('View profile') }}" data-bs-title="{{ _('View profile') }}" data-bs-toggle="tooltip">
                        {{ h.user_image((c.user if c and c.user else ''), size=22) }}
                        <span class="username">{{ c.userobj.display_name }}</span>
                      </a>
                    </li>
                  {% endblock %}
                  {% if c.userobj.sysadmin %}
                    <li>
                      <a class="btn btn-primary" href="{{ h.url_for('admin.index') }}" aria-label="{{ _('Sysadmin settings') }}" data-bs-title="{{ _('Sysadmin settings') }}" data-bs-toggle="tooltip">
                        <i class="fa fa-gavel" aria-hidden="true"></i>
                        <span class="text">{{ _('Admin') }}</span>
                      </a>
                    </li>
                  {% endif %}
                  {% block header_dashboard %}
                    <li>
                      <a class="btn btn-primary" href="{{ h.url_for('dashboard.datasets') }}" aria-label="{{ _('View dashboard') }}" data-bs-title="{{ _('View dashboard') }}" data-bs-toggle="tooltip">
                        <i class="fa fa-tachometer" aria-hidden="true"></i>
                        <span class="text">{{ _('Dashboard') }}</span>
                      </a>
                    </li>
                  {% endblock %}
                  {% block header_account_log_out_link %}
                    <li>
                      <form action="{{ h.url_for('user.logout') }}" method="post">
                        {{ h.csrf_input() }}
                        <button class="btn btn-primary" type="submit" aria-label="{{ _('Log out') }}" data-bs-title="{{ _('Log out') }}" data-bs-toggle="tooltip">
                          <i class="fa fa-sign-out" aria-hidden="true"></i>
                        </button>
                      </form>
                    </li>
                  {% endblock %}
                {% endblock %}
              </ul>
            </div>
          {% endblock %}
        </div>
      </div>
    {% endif %}
  {% endblock %}
  <header class="masthead">
    <div class="container">
      {% block header_debug %}
        {% if g.debug and not g.debug_supress_header %}
          <div class="debug">Blueprint : {{ g.blueprint }}<br />View : {{ g.view }}</div>
        {% endif %}
      {% endblock %}
      <nav class="navbar navbar-expand-lg navbar-light">
        <div class="{{ g.header_class }} navbar-left col-md-2">
          {% block header_logo %}
            {% if g.site_logo %}
              <a class="logo" href="{{ h.url_for('home.index') }}">
                <img src="{{ h.url_for_static_or_external(g.site_logo) }}" alt="{{ g.site_title }}"
                  aria-label="{{ _('Navigate to Home - {site_title}').format(site_title=g.site_title) }}"/>
              </a>
            {% else %}
              <a href="{{ h.url_for('home.index') }}">{{ g.site_title }}</a>
              {% if g.site_description %}
                <p class="mb-0">{{ g.site_description }}</p>
              {% endif %}
            {% endif %}
          {% endblock %}
        </div>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#main-navigation-toggle"
          aria-controls="main-navigation-toggle" aria-expanded="false" aria-label="{{ _('Toggle navigation') }}">
          <span class="fa fa-bars"></span>
        </button>
        <div class="main-navbar collapse navbar-collapse col-md-10" id="main-navigation-toggle">
          {% block header_site_navigation %}
            <ul class="navbar-nav mb-2 mb-lg-0 col-md-10">
              {% block header_site_navigation_tabs %}
                {% set org_type = h.default_group_type('organization') %}
                {% set group_type = h.default_group_type('group') %}

                {{ nav.link(h.url_for(dataset_type ~ '.search'), h.humanize_entity_type('package', dataset_type, 'main nav') or _('Datasets'), active_blueprints=[dataset_type, dataset_type + '_resource']) }}
                {{ nav.link(h.url_for(org_type ~ '.index'), h.humanize_entity_type('organization', org_type, 'main nav') or _('Organizations'), active_blueprints=[org_type]) }}
                {{ nav.link(h.url_for(group_type ~ '.index'), h.humanize_entity_type('group', group_type, 'main nav') or _('Groups'), active_blueprints=[group_type]) }}
                {{ nav.link(h.url_for('home.about'), _('About')) }}
              {% endblock %}
            </ul>
          {% endblock %}
          {% block header_account_notlogged %}
            {% if not c.userobj %}
              <div class="col-md-2 login">
                <a class="btn btn-primary" href="{{ h.url_for('user.login') }}">
                  {{ _('Login') }}
                  <i class="fa fa-sign-in"></i>
                </a>
              </div>
            {% endif %}
          {% endblock %}
        </div>
      </nav>
    </div>
  </header>
{% endblock %}
