<script>
  let enrolledCourses = {
    {% for course in courses.enrolled %}
      "{{ course.id }}": "{{ course.name }}",
    {% endfor %}
  };
  if (document.referrer.length == 0) {
    console.log('no referrer')
    alert("Error, please contact with your's school admin");
    setTimeout(history.back(), 4000)
  }
  else {
    let previousLink = document.referrer.split('/');
    previousLink.pop();
    let courseUUID = previousLink.pop();
    let courseName = enrolledCourses[courseUUID];
    let text = `I just finished ${courseName} Course and loved it. #SkuidSkool`;
    let link = 'https://skuidskool.com/app';
    let urls = {
      "facebook": `https://www.facebook.com/sharer/sharer.php?u=${link}`,
      "twitter": `https://twitter.com/intent/tweet?url=https://www.skuidskool.com/app&text=${encodeURIComponent(text)}%0A%0A${encodeURIComponent(link)}`,
      "linkedin": `https://www.linkedin.com/shareArticle?mini=true&url=${link}`
    }
    let platform = new URLSearchParams(window.location.search).get('platform')
    if (urls[platform]) {
      window.location.replace(urls[platform])
    }
    else {
      console.log('no platform')
      alert("Error, please contact with your's school admin");
      setTimeout(history.back(), 4000)
    }
  }
</script>