<script>
  $(document).ready(function () {
     let selfGuidedCourseReleaseHour = Number({{ course_release_hour }})
    $(".fellowship-course").css("display", "none")

    let enrollment_date = new Date(Number('{{ enrollment_date | date: "%s" }}') * 1000).setHours(selfGuidedCourseReleaseHour, 00, 00)
    console.log("Enrollment date with 9am EST start time", new Date(enrollment_date))

    const now = new Date();

    $(".fellowship-course").each(function (i) {

      let courseModule = i + 1;

      $(`.fellowship-course.module-1`).css("display", "block");

      if (courseModule > 1) {
        let daysDifference = ((30 * i) * 24 * 60 * 60 * 1000);
        let timeDiff = now.getTime() - new Date(enrollment_date).getTime();
        
        if (timeDiff >= daysDifference) {         
          console.log(`Releasing selfGuided module ${courseModule}`)
          $(`.fellowship-course.module-${courseModule}`).css("display", "block")

          if (courseModule >= 2) {
            $(`.fellowship-course.module-2-extra`).css("display", "block")
          }
        }
      }
    })

  });
</script>

