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

    let enrollment_date = new Date(Number('{{ rolling_admission_enrollment_date | date: "%s" }}') * 1000).setHours(rollingAdmissionCourseReleaseHour, 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 Rolling Admission module ${courseModule}`)
          $(`.fellowship-course.module-${courseModule}`).css("display", "block")

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

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

  });
</script>

