<script>
  const defaultPageTitle = document.title

  if (window.location.pathname == "/app/dashboard") {
    document.title = `${defaultPageTitle} | My Courses `
  } else if (window.location.pathname == "/app/learning_paths") {
    document.title = `${defaultPageTitle} | Learning Paths`
  } else if (window.location.pathname == "/app/training_events") {
    document.title = `${defaultPageTitle} | Training Events`
  } else if (window.location.pathname == "/app/upcoming-trainings") {
    document.title = `${defaultPageTitle} | Upcoming Trainings`
  }
</script>

<header class="np-header np-header-color">
  <div class="np-header-content np-max-width">
    <div class="np-hidden-desktop np-header-mobile-menu-nav">
      {% if current_person.signed_in? %}
        <button
          data-toggle-class="np-hidden"
          class="np-header-mobile-menu-nav-button fal fa-times np-hidden np-header-font-color"
          data-toggle-target=".np-header-mobile-avatar-menu,.np-header-mobile-menu-content, .np-main, .np-footer"></button>
        <button
          data-test="open-mobile-menu"
          data-toggle-class="np-hidden"
          class="np-header-mobile-menu-nav-button np-header-mobile-avatar-menu"
          data-toggle-target=".fa-times, .np-header-mobile-menu-content, .np-main, .np-footer">
          <img
            alt="{{ current_person.name }}"
            class="np-header-avatar-image"
            src="{{ current_person.avatar_url }}" />
        </button>
      {% endif %}
    </div>
    {% if current_school.logo_url %}
      <h1 class="np-header-logo">
        <a href="{% route home %}">
          <img
            alt="{{ current_school.name }}"
            class="np-header-logo-image"
            src="{{ current_school.logo_url }}" />
        </a>
      </h1>
    {% else %}
      <a href="{% route home %}" class="np-school-name np-header-font-color">
        {{ current_school.name }}
      </a>
    {% endif %}

    <div class="np-hidden-mobile np-header-desktop-nav">
      <ul class="np-header-desktop-nav-list">
        {% for link in navigations.sub_navigation %}
          {% unless link.label == "Catalog" %}
            {% assign link_url = "" %}
            {% comment %} {% if link.label == "Dashboard" %}
              {% assign link_url = "/app/courses" %}
            {% else %}
              {% assign link_url = link.url %}
            {% endif %} {% endcomment %}
            <li class="np-header-desktop-nav-item">
              <a href="{{ link.url }}" class="np-header-desktop-nav-link {% if link.label == "Events" %}np-button{% else %}np-header-font-color{% endif %} {% if link.label == "Catalog" %}link-dropdown{% endif %}">
                {% if link.label == "Courses" or link.label == "Dashboard" %}
                  My Courses
                {% elsif link.label == "Catalog" %}
                  Catalog
                  <i
                    data-test="open-catalog-dropdown"
                    data-toggle-class="np-hidden"
                    data-toggle-target=".np-catalog-dropdown-content"
                    class="far fa-chevron-down"></i>
                {% elsif link.label == "Events" %}
                  Live events
                {% else %}
                  {{ link.label }}
                {% endif %}
              </a>
              {% comment %} {% if link.label == "Catalog" %}
                <div class="np-catalog-dropdown-content np-hidden">
                  <form
                    class="np-header-search"
                    data-test="mobile-search"
                    method="get"
                    action="{% route search %}">
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      width="21"
                      height="20"
                      viewBox="0 0 21 20"
                      fill="none">
                      <path
                        d="M18 17.5L15.0834 14.5833M17.1667 9.58333C17.1667 13.4954 13.9954 16.6667 10.0833 16.6667C6.17132 16.6667 3 13.4954 3 9.58333C3 5.67132 6.17132 2.5 10.0833 2.5C13.9954 2.5 17.1667 5.67132 17.1667 9.58333Z"
                        stroke="#011638"
                        stroke-width="1.66667"
                        stroke-linecap="round"
                        stroke-linejoin="round" />
                    </svg>
                    <input
                      aria-label="{% t .search %}"
                      class="np-dropdown-search-input"
                      type="text"
                      name="q"
                      placeholder="{% t .search %}" />

                  </form>
                  {% for filter in courses.filters limit: 3 %}
                    <a href="/app/catalog?filter[category_uuid][in][]={{filter.value}}" class="dropdown-category-link">{{ filter.name }}</a>
                  {% endfor %}
                </div>
              {% endif %} {% endcomment %}
            </li>
            {% endunless %}
        {% endfor %}
        {% for website_navigation in navigations.header_navigations_external %}
          <li class="np-header-desktop-nav-item">
            <a
              href="{{ website_navigation.path }}"
              class="np-header-desktop-nav-link np-header-font-color"
              target="_blank">
              {{ website_navigation.name }}
            </a>
          </li>
        {% endfor %}
      </ul>

    </div>

    {% if current_person.signed_in? %}
      {% else %}
        <a
          class="np-header-sign-in np-header-desktop-nav-link np-header-font-color"
          aria-label="{% t shared.sign_in %}"
          href="{% route login %}">
          {% t shared.sign_in %}
        </div>
    {% endif %}
  </div>
</header>

<div class="np-hidden-desktop">
  <div class="np-header-mobile-menu-content np-hidden">
    {% if current_person.signed_in? %}
      <img
        alt="{{ current_person.name }}"
        class="np-header-mobile-menu-content-avatar"
        src="{{ current_person.avatar_url }}" />
      <div class="np-header-mobile-menu-content-name">
        {{ current_person.name }}
      </div>
    {% endif %}
    <div class="np-header-mobile-menu-content-nav">
      <form
        class="np-header-search"
        data-test="mobile-search"
        method="get"
        action="{% route search %}">
        <input
          aria-label="{% t .search %}"
          class="np-header-search-input"
          type="text"
          name="q"
          placeholder="{% t .search %}" />
        <i class="np-header-search-icon far fa-search"></i>
      </form>
      {% for website_navigation in navigations.header_navigations %}
        <a
          href="{{ website_navigation.path }}"
          class="np-header-mobile-menu-content-button"
          {% if website_navigation.external? %}
          target="_blank"
          {% endif %}>
          {{ website_navigation.name }}
        </a>
      {% endfor %}
      <div class="np-header-mobile-menu-content-line"></div>
      {% unless current_school.sso_active? %}
        <a class="np-header-mobile-menu-content-button" href="{% route account %}">
          {% t.profile_settings %}
        </a>
      {% endunless %}
      <a class="np-header-mobile-menu-content-button np-danger" href="{% route logout %}">
        {% t.sign_out %}
      </a>
    </div>
  </div>
</div>

{% include "messages" %}

<style>

  .np-header-desktop-nav-list {
    align-items: center;
  }

  .np-header-desktop-nav-item {
    position: relative;
  }

  .np-header-desktop-nav-item .np-header-desktop-nav-link {
    font-size: 18px;
    font-weight: 600;
    line-height: 24px;
    letter-spacing: -0.18px;
    position: relative;
  }

  .np-header-desktop-nav-link.np-button {
    display: inline-flex;
    color: #fff;
  }

  .np-header-desktop-nav-link.link-dropdown i.np-hidden {
    display: inline-block !important;
    transform: rotate(180deg);
  }

  .np-catalog-dropdown-content {
    position: absolute;
    top: 78px;
    background-color: #011638;
    z-index: 50;
    padding: 24px;
    width: 209px;
    right: 0;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
  }

  .np-dropdown-search-input {
    padding: 10px 14px 10px 34px;
    border-radius: 8px;
    width: 100%;
    border: none;
  }

  .dropdown-category-link {
    color: #E7E9F5;
    text-decoration: none;
    display: block;
    margin: 14px 0 6px;
    font-weight: 600;
  }

  .np-header-search svg {
    position: absolute;
    top: 8px;
    left: 8px;
  }

  @media screen and (min-width: 768px) {
    .np-header {
      height: 100px;
      padding-left: 0;
      padding-right: 0;
    }
  }
</style>