{% include "modified_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 %}"
        >
          Profile Settings
        </a>
      {% endunless %}
      <a
        class="np-header-mobile-menu-content-button np-danger"
        href="{% route logout %}"
      >
        Sign Out
      </a>
    </div>
  </div>
</div>
{% include "messages" %}
{% include "course_version_outdated_alert", courses: courses.enrolled %}

<div class="np-homepage-hero">
  <img class="np-homepage-hero-image"
    src="{{ homepage.artwork_url }}"
    alt="{{ homepage.headline }}"
  />
  <div class="np-homepage-hero-content">
    <div class="np-homepage-headline np-header-font-color">
      {{ homepage.headline }}
    </div>
    <div class="np-homepage-subheadline np-header-font-color">
      {{ homepage.subheadline }}
    </div>
  </div>
</div>

{% include "sub_navigation" %}
<main class="np-main np-dashboard np-subpage-container np-max-width">
  <div class="np-dashboard-header">
    <div class="np-resource-title">Hi {{current_person.first_name}}! &#128075;</div>
    <div class="np-resource-subtitle">This is what's relevant to you right now in Northpass Academy.</div>
  </div>
  {% comment %}<div class="row np-flex-center">
    <div class="col-xs-12 col-md-8">
      {% if features.learning_paths? %}
        <div class="np-dashboard-resources-title">
          {% t shared.learning_paths %}
        </div>
        {% include "learning_paths_index", items: learning_paths.enrolled %}
      {% endif %}
    </div>    
    <div class="np-grid-spacing col-xs-12 col-md-4 progress-section">
      <div class="np-dashboard-resources-title">Course Progress</div>
      {% include "widget_course_progress" %}
    </div>
  </div>{%endcomment%}

  <div class="row dashboard-section-courses">
    <div class="col-xs-12">
      {% if courses.enrolled.any? %}
        {% if categories.enrolled.any? %}
          {% assign all_categories = categories.enrolled | map: "name" %}
          {% for enrolled_category in all_categories %}
            <div class="np-md-flex-wrapper">
              <div>
                <div class="np-dashboard-resources-title">
                  Topic
                </div>
                <div class="np-dashboard-resources-category">
                  {{ enrolled_category }}
                </div>
              </div>       
              {% 
                include "filter_by_progress", 
                label: "Filter by Progress:", 
                default_option: "All Courses",
                topic: enrolled_category,
              %}
            </div>
            {% 
              include "carousel_courses", 
              items: courses.enrolled,
              topic: enrolled_category,
            %}
          {% endfor %}
        {% else %}
          {% assign enrolled_category = "Not Categorized" %}
          <div class="np-md-flex-wrapper">
            <div>
              <div class="np-dashboard-resources-title">
                Topic
              </div>
              <div class="np-dashboard-resources-category">
                {{ enrolled_category }}
              </div>
            </div>       
            {% 
              include "filter_by_progress", 
              label: "Filter by Progress:", 
              default_option: "All Courses",
              topic: enrolled_category,
            %}
          </div>
          {% 
            include "carousel_courses", 
            items: courses.enrolled,
            topic: enrolled_category,
          %}
        {% endif %}
      {% else %}
        <div class="np-dashboard-resources-title" style="margin-bottom:19px;">
          Courses
        </div>
        {% capture message %}
          {% t shared.zero_state.courses.index,
            key: current_school.course_vocabulary
          %}
        {% endcapture %}
        <div style="margin-bottom:3rem;">
          {% include "courses_zero_state", message: message %}
        </div>
      {% endif %}
    </div>
  </div>
</main>
{% include "footer" %}

<style>
  .np-homepage-hero{
     background: #34abe2; 
     margin-top: -4rem;
     z-index: -1; 
  }
</style>>
<script>
  // Creates the custom dropdown and dropdown functionality
  var x, i, j, l, ll, selElmnt, a, b, c;
  /* Look for any elements with the class “select-wrapper”: */
  x = document.getElementsByClassName("progress-filter");
  l = x.length;
  for (i = 0; i < l; i++) {
    selElmnt = x[i].getElementsByTagName("select")[0];
    ll = selElmnt.length;
    a = document.createElement("DIV");
    a.setAttribute("class", "select-selected");
    a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
    x[i].appendChild(a);
    b = document.createElement("DIV");
    b.setAttribute("class", "select-items select-hide");
    for (j = 1; j < ll; j++) {
      c = document.createElement("DIV");
      c.innerHTML = selElmnt.options[j].innerHTML;
      c.addEventListener("click", function(e) {
          var y, i, k, s, h, sl, yl;
          s = this.parentNode.parentNode.getElementsByTagName("select")[0];
          sl = s.length;
          h = this.parentNode.previousSibling;
          for (i = 0; i < sl; i++) {
            if (s.options[i].innerHTML == this.innerHTML) {
              s.selectedIndex = i;
              h.innerHTML = this.innerHTML;
              y = this.parentNode.getElementsByClassName("same-as-selected");
              yl = y.length;
              for (k = 0; k < yl; k++) {
                y[k].removeAttribute("class");
              }
              this.setAttribute("class", "same-as-selected");
              break;
            }
          }

          filterCourses(this);
    
          h.click();
      });
      b.appendChild(c);
    }
    x[i].appendChild(b);
    a.addEventListener("click", function(e) {
      e.stopPropagation();
      closeAllSelect(this);
      this.nextSibling.classList.toggle("select-hide");
      this.classList.toggle("select-arrow-active");
    });
  }

  function closeAllSelect(elmnt) {
    var x, y, i, xl, yl, arrNo = [];
    x = document.getElementsByClassName("select-items");
    y = document.getElementsByClassName("select-selected");
    xl = x.length;
    yl = y.length;
    for (i = 0; i < yl; i++) {
      if (elmnt == y[i]) {
        arrNo.push(i)
      } else {
        y[i].classList.remove("select-arrow-active");
      }
    }
    for (i = 0; i < xl; i++) {
      if (arrNo.indexOf(i)) {
        x[i].classList.add("select-hide");
      }
    }
  }

  /* If the user clicks anywhere outside the select box,
  then close all select boxes: */
  document.addEventListener("click", closeAllSelect);
  $(".select-items div").each(function() {
    if($( this ).text() == $(".select-selected").text()) {
      $(this).addClass("same-as-selected");
    }
  });

  function filterCourses(selectedItem) {
        
    let filterGroup = $(selectedItem).closest(".progress-filter").data("topic");
    let selectedFilter = $(selectedItem).text().replace(" ", "-").toLowerCase();
    let carouselGroup = $('.courses-carousel[data-topic="' + filterGroup + '"]');

    carouselGroup.slick('slickUnfilter');

    if (selectedFilter != "all-courses") {
      carouselGroup.slick('slickFilter', `.${selectedFilter}`);
    }

  }
  $(".np-sub-navigation-content-item-link:contains('Dashboard')").parent().addClass("np-sub-navigation-content-item-active")
</script>
