{% assign available_school_categories = '' | split: '' %}
{% assign enrolled_courses = courses.enrolled %}
{% for course in enrolled_courses %}
  {% for cat in course.categories %}
    {% assign cat_name = cat.name | split: '!@#$%^&*()' %}
    {% assign available_school_categories = available_school_categories | concat: cat_name %}
  {% endfor %}
{% endfor %}
{% assign enrolled_learning_paths = learning_paths.enrolled %}
{% for learning_path in enrolled_learning_paths %}
  {% for lp_cat in learning_path.categories %}
    {% assign lp_cat_name = lp_cat.name | split: '!@#$%^&*()' %}
    {% assign available_school_categories = available_school_categories | concat: lp_cat_name %}
  {% endfor %}
{% endfor %}
{% assign unique_school_categories = available_school_categories | uniq | sort %}

{% assign resource_bundles_to_display = "" %}
{% if features.learning_paths? %}
  {% if enrolled_learning_paths.any? %}   
    {% if current_person.properties.access_level == "EXPERIENCED" %}
      {% assign resource_bundles_to_display = current_school.properties.featured_resource_bundles_experienced | downcase %}
    {% elsif current_person.properties.access_level == "BEGINNER" %}
      {% assign resource_bundles_to_display = current_school.properties.featured_resource_bundles_beginner | downcase %}
    {% endif %}
  {% endif %}
{% endif %}

{% assign resource_bundles_to_display_array = resource_bundles_to_display | split: "," %}

{% capture icon %}
  fa-arrow-left{% endcapture %}
{% include "mobile_header", title: "Resource Center", back_icon: icon, back_link: "javascript:sendMessage();" %}
{% include "sub_navigation" %}
<main class="np-main np-courses np-subpage-container np-max-width">
  {% if current_person.signed_in? %}
    <div class="np-courses-search np-header-search-expanded">
      <form
        action="{% route search %}"
        method="get"
        data-test="mobile-search">
        <i class="np-header-search-icon far fa-search"></i><input
          aria-label="Search courses"
          class="np-header-search-input np-header-font-background-color"
          type="text"
          name="q"
          placeholder="Search" /></form>
    </div>
  {% endif %}
  {% if current_person.properties.show_welcome_message %}
    <div class="intro-msg"><div class="intro-msg-icon-wrapper"><div class="intro-msg-icon"></div></div><div class="intro-msg-text">Questions? We can help! Check out these optional resources to get the most out of the Spark Driver&trade; app.</div></div>
  {% endif %}
  {% if courses.enrolled.any? %}
    <div class="recommended-courses-section">
      <div class="np-courses-section-label">Featured</div>
      <div class="recommended-courses-carousel-outer-container">
        <div class="recommended-courses-carousel">
          {% if features.learning_paths? %}
            {% if enrolled_learning_paths.any? %}
              {% for bundle in resource_bundles_to_display_array %}
                {% assign bundle_name = bundle | strip | escape_once %}
                {% for learning_path in enrolled_learning_paths %}
                  {% assign lp_title_downcase = learning_path.name | downcase | strip | escape_once %}
                  {% if lp_title_downcase contains bundle_name %}
                    <div class="course-slide lp-slide">                     
                      {% include "cards_learning_path" with learning_path, enrolled_courses: enrolled_courses %}
                    </div>
                    {% break %}
                  {% endif %}
                {% endfor %}
              {% endfor %}
            {% endif %}
          {% endif %}
          {% for course in enrolled_courses %}
            {% if course.properties.is_recommended_course == true %}
              {% if course.properties.access_level == current_person.properties.access_level %}
                <div
                  class="course-slide"
                  data-initialpublishdate="{{course.properties.initial_publish_date}}"
                  data-position="{{course.properties.featured_course_position}}">
                  {% include "cards_course" with course %}
                </div>
              {% endif %}
            {% endif %}
          {% endfor %}
        </div>
      </div>
    </div>
  {% endif %}
  <div class="all-categories-section">
    <div class="np-courses-section-label" style="margin-bottom:15px;">All Categories</div>
    <div class="category-cards-wrapper">
      {% include "category_cards", school_categories: unique_school_categories %}
    </div>
  </div>
</main>

<script>
  $(document).ready(function() {
    const showWelcomeMessage = '{{current_person.properties.show_welcome_message}}'
    if (showWelcomeMessage == 'true') {
      let userData = {
        learner_uuid: '{{current_person.id}}'
      }
      const schoolUuid = '{{current_school.id}}'
      hideWelcomeMessage(userData, schoolUuid)
    }
  })
</script>