{% include "header" %}
{% include "course_version_outdated_alert", courses: courses.in_catalog %}
{% comment %}{% include "sub_navigation" %}{% endcomment %}
{% comment %} https://s3.amazonaws.com/static.northpass.com/Crayon/acceleratorBadge.png {% endcomment %}
{% comment %} https://s3.amazonaws.com/static.northpass.com/Crayon/activatorBadge.png {% endcomment %}
{% comment %} https://s3.amazonaws.com/static.northpass.com/Crayon/architectBadge.png {% endcomment %}

{% assign architect_course_done = false %}
{% assign activator_course_done = false %}
{% assign accelerator_course_done = false %}

{% assign architect_course_in_progress = false %}
{% assign activator_course_in_progress = false %}
{% assign accelerator_course_in_progress = false %}


{% assign architect_course_started = true %}
{% assign activator_course_started = true %}
{% assign accelerator_course_started = true %}

{% for course in courses.in_catalog %}
  {% if course.name == 'Architect Certification Course'%}
    {% if course.progress == 100  %}
      {% assign architect_course_done = true %}
      {% elsif course.progress > 0 and course.progress < 100 %}
        {% assign architect_course_in_progress = true %}
        {% else %}
        {% assign architect_course_started = false %}
    {% endif %}
  {% endif %}
  {% if course.name == 'Activator Certification Course'%}
    {% if course.progress == 100  %}
      {% assign activator_course_done = true %}
      {% elsif course.progress > 0 and course.progress < 100 %}
        {% assign activator_course_in_progress = true %}
        {% else %}
        {% assign activator_course_started = false %}
    {% endif %}
  {% endif %}
  {% if course.name == 'Accelerator Certification Course'%}
    {% if course.progress == 100  %}
      {% assign accelerator_course_done = true %}
      {% elsif course.progress > 0 and course.progress < 100 %}
        {% assign accelerator_course_in_progress = true %}
        {% else %}
        {% assign accelerator_course_started = false %}
    {% endif %}
  {%endif%}
{% endfor %}

<section class="dashboard-section">
  <main class="np-main np-dashboard np-subpage-container np-max-width">
    <div class="row np-flex-center heading">
      <div class="col-xs-12">
        <div class="np-dashboard-header">
          <div class="np-resource-title"><span id="visitCount"></span>, {{current_person.first_name}}! 

          {% assign incomplete_course_count = 0 %}
          {% assign default_course = 'Architect Certification Course' %}
          
          {% if architect_course_started == true and architect_course_done == false %}
            Ready to complete the Architect Certification Course?
          {% elsif activator_course_started == true and activator_course_done == false %}
            Ready to complete the Activator Certification Course?
          {% elsif accelerator_course_started == true and accelerator_course_done == false %}
            Ready to complete the Accelerator Certification Course?
          {% else %}
            {% if architect_course_done == false %}
              {% assign incomplete_course_count = incomplete_course_count | plus: 1 %}
            {% endif %}
          
            {% if activator_course_done == false %}
              {% assign incomplete_course_count = incomplete_course_count | plus: 1 %}
            {% endif %}
          
            {% if accelerator_course_done == false %}
              {% assign incomplete_course_count = incomplete_course_count | plus: 1 %}
            {% endif %}
          
            {% if architect_course_done == true %}
              {% assign default_course = 'Activator Certification Course' %}
            {% endif %}
          
            {% if incomplete_course_count > 1 and default_course != 'Architect Certification Course' %}
              Ready to complete the Accelerator Certification Course?
            {% elsif incomplete_course_count > 0 %}
              Ready to complete the {{ default_course }}?
            {% else %}
              {% if architect_course_done == true and activator_course_done == false and accelerator_course_done == false %}
                Ready to begin Accelerator Certification Course?
              {% elsif activator_course_done == true and accelerator_course_done == false and architect_course_done == false %}
                Ready to begin Architect Certification Course?
              {% elsif accelerator_course_done == true and activator_course_done == false and architect_course_done == false %}
                Ready to begin Architect Certification Course?
              {% else %}
                You've completed every available course. 🎉
              {% endif %}
            {% endif %}
          {% endif %}
          
          
          </div>
          {% comment %}<div class="np-resource-subtitle">This is what’s relevant to you right now in Competitive Advantage Academy</div>{%endcomment%}
        </div>
      </div>
    </div>
  
      <div class="row dashboard-section-courses">
        <div class="col-xs-12 col-sm-6 col-lg-4">
  
          {% for course in courses.in_catalog %}
            {% if course.name == 'Activator Certification Course' %}
              <div class="np-md-flex-wrapper" style="text-align: center;">
                <div class="np-dashboard-resources-title course-progress">
                  {% if course.progress == 0 %}
                    ⛔️ NOT STARTED
                    {% elsif course.progress > 0 and course.progress < 100%}
                      ✍️ IN PROGRESS
                      {% elsif course.progress == 100 %}
                      🎉 COMPLETE
                  {% endif %}
                </div>
              </div>
              {% include 'cards_course' with course %}
            {% endif %}
          {% endfor %}
        </div>
  
        <div class="col-xs-12 col-sm-6 col-lg-4">
          {% for course in courses.in_catalog %}
            {% if course.name == 'Architect Certification Course' %}
              <div class="np-md-flex-wrapper" style="text-align: center;">
                <div class="np-dashboard-resources-title course-progress">
                  {% if course.progress == 0 %}
                    ⛔️ NOT STARTED
                    {% elsif course.progress > 0 and course.progress < 100%}
                      ✍️ IN PROGRESS
                      {% elsif course.progress == 100 %}
                      🎉 COMPLETE
                  {% endif %}
                </div>
              </div>
              {% include 'cards_course' with course %}
            {% endif %}
          {% endfor %}
        </div>
  
        <div class="col-xs-12 col-sm-6 col-lg-4">
          {% for course in courses.in_catalog %}
            {% if course.name == 'Accelerator Certification Course' %}
              <div class="np-md-flex-wrapper" style="text-align: center;">
                <div class="np-dashboard-resources-title course-progress">
                  {% if course.progress == 0 %}
                    ⛔️ NOT STARTED
                    {% elsif course.progress > 0 and course.progress < 100%}
                      ✍️ IN PROGRESS
                      {% elsif course.progress == 100 %}
                      🎉 COMPLETE
                  {% endif %}
                </div>
              </div>
              {% include 'cards_course' with course %}
            {% endif %}
          {% endfor %}
        </div>
      </div>
  
    </div>
    </div>
  </main>
</section>
{% include "footer" %}

<style>
  .dashboard-section, .np-dashboard {
    background: #89d9e1;
  }
  .course-progress {
    color: #fff;
    font-size: 1.5rem;
  }
  .heading {
    margin-bottom: 2rem;
  }
  .np-resource-title {
    text-transform: none;
  }
</style>

<script>
  function incrementVisitCount() {
    var visitCount = getCookie('visitCount');
    if (visitCount) {
      visitCount = parseInt(visitCount) + 1;
    } else {
      visitCount = 1;
    }
    setCookie('visitCount', visitCount);

    console.log(visitCount);

    if (visitCount == 1) {
    document.getElementById('visitCount').innerHTML = "Welcome";
    }
    else document.getElementById('visitCount').innerHTML = "Welcome back";
  }

  function getCookie(name) {
    var cookieName = name + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var cookieArray = decodedCookie.split(';');
    for (var i = 0; i < cookieArray.length; i++) {
      var cookie = cookieArray[i];
      while (cookie.charAt(0) === ' ') {
        cookie = cookie.substring(1);
      }
      if (cookie.indexOf(cookieName) === 0) {
        return cookie.substring(cookieName.length, cookie.length);
      }
    }
    return null;
  }

  function setCookie(name, value) {
    var expirationDate = new Date();
    expirationDate.setFullYear(expirationDate.getFullYear() + 1); // Ustawienie daty wygaśnięcia pliku cookie na za rok
    document.cookie = name + "=" + value + "; expires=" + expirationDate.toUTCString() + "; path=/";
  }

  incrementVisitCount();
</script>