{% load i18n %}
<div class="sequence timed-exam entrance" data-exam-id="{{exam_id}}">
  <h3>
    {% blocktrans %}
    {{ exam_name }} is a Timed Exam ({{total_time}})
    {% endblocktrans %}
  </h3>
  <p>
    {% trans "This exam has a time limit associated with it." %}
    <strong>
      {% trans "To pass this exam, you must complete the problems in the time allowed." %}
    </strong>
    {% trans "After you select " %}
    <strong>
      {% trans "I am ready to start this timed exam," %}
    </strong>
    {% trans "you will have "%} {{total_time|lower}} {% trans " to complete and submit the exam." %}
  </p>
  <button class="gated-sequence start-timed-exam action-primary" data-ajax-url="{{enter_exam_endpoint}}" data-exam-id="{{exam_id}}">
    <a>
      {% blocktrans %}
        I am ready to start this timed exam.
      {% endblocktrans %}
      <span class="icon fa fa-arrow-circle-right" aria-hidden="true"></span>
    </a>
  </button>
</div>
{% if not hide_extra_time_footer %}
  {% include 'timed_exam/footer.html' %}
{% endif %}

<script type="text/javascript">

  var inProcess = false;

  var disableClickEvent = function () {
    inProcess = true;
    $('body').css('cursor', 'wait');
    $('.start-timed-exam').css('cursor', 'wait');
  };

  var enableClickEvent = function () {
    inProcess = false;
    $('body').css('cursor', 'auto');
    $('.start-timed-exam').css('cursor', 'auto');
  };

  $('.start-timed-exam').click(function () {
      if (!inProcess) {
        disableClickEvent();
        var action_url = $(this).data('ajax-url');
        var exam_id = $(this).data('exam-id');

        $.post(
          action_url,
          {
            "exam_id": exam_id,
            "start_clock": true
          },
          function (data) {
            // reload the page, because we've unlocked it
            location.reload();
          }
        ).fail(function(){
          enableClickEvent();
          var msg = gettext(
            "There has been a problem starting your exam.\n\n" +
            "Possible reasons are that your account has not been fully activated,\n" +
            "you are experiencing a network connection problem, or there has been\n" +
            "a service disruption. Please check these potential problems and try again."
          );
          alert(msg);
        });
      } else {
        return false;
      }
    }
  );
</script>
