
{% include "custom_header" %}
{% include "course_version_outdated_alert", courses: courses.enrolled %}

<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}}!</div>
    <div class="np-resource-subtitle">This is what's relevant to you right now
      in Crayon Onboarding Academy.</div>
  </div>
  <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.available %}
      {% 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>

  <div class="row dashboard-section-courses">
    <div class="col-xs-12">
      {% if courses.in_catalog.any? %}
            <div class="np-md-flex-wrapper onboarding-wrapper">
              <div>
              </div>
              {%
                include "filter_by_progress",
                label: "Filter by Progress:",
                default_option: "All Courses",
                topic: "enrolled_category",
              %}
            </div>
            {%
              include "carousel_courses",
              items: courses.in_catalog,
              topic: "enrolled_category",
            %}
      {% 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>

   <div class="row dashboard-section-events">
    <div class="col-xs-12">
      <div class="np-dashboard-resources-title" style="margin-bottom: 5px;">
        Training Events
      </div>
      <div class="np-dashboard-resources-category" style="margin-bottom: 19px;">
        Discover online events to maximize your learning
      </div>
      {% if training_events.available.any? %}
        {%
        include "carousel_events",
        items: training_events.available,
        %}
      {% else %}
      <div style="margin-bottom:3rem;">
        {% include "training_events_zero_state" %}
      </div>

      {% endif %}
    </div>
  </div>

</main>
{% include "footer" %}

<style>
  @media screen and (max-width: 1024px) {
    .progress-section {
      padding-left: 0.5rem
    }
  }
  .np-dashboard {
    background: #fff;
    padding-top: 160px;
  }
  body {
    background: #fff;
  }
  .right-arrow {
    display: none !important;
    position: relative;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    font-size: 2rem;
    margin-left: 2rem;
    cursor: pointer;
  }
  .left-arrow {
    display: none !important;
    position: relative;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: flex-start;
    font-size: 2rem;
    margin-left: -2rem;
    z-index: 11;
    cursor: pointer;
  }
  .np-resource-title {
    font-size: 40px;
    color: #000;
  }
  .np-resource-subtitle, .np-dashboard-resources-title, .np-dashboard-resources-category {
    color: #000;
  }
  .np-header {
    position: fixed;
    border-bottom: 1px solid rgba(0,0,0,0.25);
    }
  .onboarding-wrapper {
    padding: 2rem 0;
  }
</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>
