{% comment %}This section of code will iterate over all courses in a learning path and average out the completion per course compared to the total of the LP {% endcomment %}
{% assign total_progress = 0 %}
{% assign completed_progress = 0 %}

{% for item in learning_path.items %}
  {% if item.course? %}
    {% assign total_progress = total_progress | plus: 100 %}

    {% unless item.progress == 0 %}
      {% assign completed_progress = completed_progress | plus: item.progress %}
    {% endunless %}
  {% endif %}
{% endfor %}

{% assign total_progress = total_progress | times: 0.01 %}
{% assign calculated_progress = completed_progress | divided_by: total_progress %}

{% if learning_path.enrolled? %}
  <div class="np-top-cta-progress-content">
    <div class="np-top-cta-progress-title np-text-title">
      {% t .progress %}
    </div>
    <div class="np-progress-bar-container">
      <div
        style="width: {{ calculated_progress }}%"
        class="np-button-background-color np-card-progress-bar">
      </div>
    </div>
    <div class="np-top-cta-progress-text
      {% if learning_path.completed? %} np-color-success {% else %} np-button-color {% endif %}
    ">
    {% if calculated_progress == 0 %}
      {% t shared.progress, count: learning_path.progress %}
    {% else %}
      {{calculated_progress | ceil }}% Completed
    {% endif %}
    </div>
  </div>
{% endif %}

<a
  class="np-top-button np-button-font-color np-button np-button-big"
{% if learning_path.enrolled? %}
  {% if learning_path.current_item.course? %}
    href="{% route learning_path_course, id: learning_path.current_item.id, learning_path_id: learning_path.id %}"
  {% elsif learning_path.current_item.training_event? %}
    href="{% route training_session, id: learning_path.current_item.id %}"
  {% endif %}
{% else %}
    href="{% route learning_path_enrollment, code: learning_path.enrollment_code %}"
{% endif %}
>
  {% if learning_path.enrolled? == false %}
    {% t shared.enroll %}
  {% elsif calculated_progress == 0 %}
    {% t shared.learning_path.start %}
  {% elsif calculated_progress == 100 %}
    {% t shared.learning_path.view %}
  {% else %}
    {% t shared.continue %}
  {% endif %}
</a>