<script>
  $(document).ready(function () {
    console.log("Begin Self Guided Script")

    let selfGuidedCourseReleaseHour = Number({{ course_release_hour }})
    $(".fellowship-course").css("display", "none")

    let selfGuided_enrollment_date = new Date(Number('{{ self_guided_enrollment_date | date: "%s" }}') * 1000).setHours(selfGuidedCourseReleaseHour, 00, 00)
    console.log("Selg Guided enrollment date with 9am EST start time", new Date(selfGuided_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(selfGuided_enrollment_date).getTime();
        
        if (timeDiff >= daysDifference) {         
          console.log(`Releasing selfGuided module ${courseModule}`)
          $(`.fellowship-course.module-${courseModule}`).css("display", "block")
        }
      }
    })

  });
</script>

