<div class="np-homepage-featured np-max-width">
  <div class="row">
    <div class="col-xs-12">
      <div class="np-homepage-featured-text">
        <div class="np-homepage-headline">
          Quick Learn
        </div>
      </div>
      {% if items.size > 0 %}
        {% assign quick_learn_courses_count = 0 %}
        <div class="quick-learn-wrapper">
          <div class="quick-learn-slider">
            {% assign quick_learn_items_alphabetical = items | sort: "name" %}
            {% for course in quick_learn_items_alphabetical %}
              {% if quick_learn_courses_count < 3 %}
                {% unless course.properties.is_article_course %}
                  {% assign is_quick_learn = false %}

                  {% for cat in course.categories %}
                    {% assign cat_name = cat.name | downcase %}
                    {% if cat_name == "quick learn" %}
                      {% assign is_quick_learn = true %}
                    {% endif %}
                  {% endfor %}

                  {% if is_quick_learn %}
                    {% assign quick_learn_courses_count = quick_learn_courses_count | plus: 1 %}

                    <div class="quick-learn-slide" data-position="{{course.properties.course_position}}">
                      {% include "cards_course" with course %}
                    </div>
                  {% endif %}
                {% endunless %}
              {% endif %}
            {% endfor %}
          </div>
        </div>

        {% if quick_learn_courses_count > 0 %}
        {% else %}
          <div class="np-homepage-featured-empty">
            <div class="np-zero-state-text">
              Sorry! There is no quick learning content at the moment. Be sure to check back here later.
            </div>
            <img class="np-zero-state-courses" alt="Sorry! There is no Featured content at the moment. Be sure to check back here later." />
          </div>
        {% endif %}
      {% else %}
        <div class="np-homepage-featured-empty">
          <div class="np-zero-state-text">
            Sorry! There is no quick learning content at the moment. Be sure to check back here later.
          </div>
          <img class="np-zero-state-courses" alt="Sorry! There is no Featured content at the moment. Be sure to check back here later." />
        </div>
      {% endif %}
    </div>
  </div>
</div>


<script>

  window.addEventListener("load", (event) => {
  var indexes = document.querySelectorAll(".quick-learn-slider .quick-learn-slide");
  var indexesArray = Array.from(indexes);

  const sortByPosition = arr => {
    const positionSorter = (a, b) => {
        return a.dataset.position - b.dataset.position;
    }
    arr.sort(positionSorter);
  };

  sortByPosition(indexesArray);

  document.querySelector(".quick-learn-slider").innerHTML = ""

  indexesArray.forEach(e =>
      document.querySelector(".quick-learn-slider").appendChild(e));
  

  initQuickLearnCoursesCarousel()

  });

  function initQuickLearnCoursesCarousel() {
  var quickLearnSlider = tns({
    container: '.quick-learn-slider',
    items: 1,
    slideBy: 'page',
    autoplay: false,
    gutter: 8,
    controls:false,
    navPosition:"bottom",
    loop: false,
    mouseDrag: true,
    speed: 500,
    responsive: {
      600: {
        items: 2,
      },
      768: {
        items:3,
        gutter: 16,
        nav: false,
      }
    }
  });
  }
</script>


<style>
  .quick-learn-wrapper {
    margin: 0 -8px;
  }

  .np-homepage-featured {
    padding: 0 16px;
    margin-bottom: 56px;
  }

  .np-homepage-featured-text {
    padding: 0 0 32px;
    text-align: left;
    display: flex;
  }

  .np-homepage-featured-text .np-homepage-headline {
    font-weight: 400;
    font-size: 24px;
    line-height: 32px;
    color: #333;
    align-self: flex-start;
  }

  .quick-learn-carousel-controls {
    align-self: flex-end;
    display: flex;
  }

  .quick-learn-carousel-controls .carousel-control {
    margin: 0 8px;
    background-color: #ebe8f3;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #3c228a;
    cursor: pointer;
    transition: opacity 0.2s;
  }

  .quick-learn-carousel-controls .carousel-control[aria-disabled='true'] {
    opacity: 0.3;
    cursor: default;
  }

  .quick-learn-carousel-controls .carousel-control.next-arrow {
    margin-right: 0;
  }

  .quick-learn-slider {
    display: flex;
  }

  .quick-learn-slide {
    margin-bottom: 12px;
  }

  .quick-learn-slide .np-card {
    margin: 0 auto;
    padding: 0;
    height: 100%;
  }

  .quick-learn-slide .np-card-container {
    height: 100%;
    margin: 0 8px;
  }

  .featured-see-more-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
  }

  .featured-see-more-wrapper a {
    color: #3C228A;
  }

  @media (min-width: 768px) {
    .np-homepage-featured-text {
      flex-direction: row;
      justify-content: space-between;
    }

    .np-homepage-featured-text .np-homepage-headline {
      font-size: 32px;
      line-height: 40px;
    }

    .featured-see-more-wrapper {
      margin-top: 12px;
    }
  }
</style>