{% assign uniq_lps = '' %}

<div class="np-learning-paths-resources">
  {% if items.any? %}
    {% for learning_path in items %}
      {% for category in learning_path.categories %}
				<script> console.log('{{ learning_path.name }}')</script>
        {% unless category.name == 'Category Advisors' %}
          {% unless uniq_lps contains learning_path.name %}
            {% include "cards_learning_path" with learning_path %}
            {% assign uniq_lps = uniq_lps |  append: learning_path.name %}
          {% endunless %}
        {% endunless %}
      {% endfor %}
    {% endfor %}
  {% else %}
    <div class="np-learning-paths-resources-container">
      <div class="np-zero-state-text">
        No tienes asignadas rutas de aprendizaje.
      </div>
      <img class="np-zero-state-learning-paths" alt="{% t .empty %}" />
    </div>
  {% endif %}
</div>


<script>
  function sortGrowLps() {
    const lpCards = Array.from(document.querySelectorAll('.lp-card'));

    lpCards.sort((a, b) => {
      const aPrioritise = a.getAttribute('prioritise') === 'true';
      const bPrioritise = b.getAttribute('prioritise') === 'true';

      return bPrioritise - aPrioritise;
    });


    const parentElement = lpCards[0].parentNode;


    while (parentElement.firstChild) {
      parentElement.removeChild(parentElement.firstChild);
    }


    lpCards.forEach(card => parentElement.appendChild(card));
  }
  document.addEventListener("DOMContentLoaded", () => {
    sortGrowLps();
  });
</script>
