{% load i18n %}
<div class="sequence timed-exam completed" data-exam-id="{{exam_id}}">
  <h3>
    {% blocktrans %}
      Are you sure that you want to submit your timed exam?
    {% endblocktrans %}
  </h3>
  <p>
    {% blocktrans %}
      Make sure that you have selected "Submit" for each problem before you submit your exam.
    {% endblocktrans %}
  </p>
  <p>
    {% blocktrans %}
      After you submit your exam, your exam will be graded.
    {% endblocktrans %}
  </p>
  <button type="button" name="submit-proctored-exam" class="exam-action-button btn btn-pl-primary btn-base" data-action="submit" data-exam-id="{{exam_id}}" data-change-state-url="{{change_state_url}}">
    {% blocktrans %}
      Yes, submit my timed exam.
    {% endblocktrans %}
  </button>
  {% if does_time_remain %}
    <button type="button" name="goback-proctored-exam" class="exam-action-button btn btn-secondary btn-base" data-action="start" data-exam-id="{{exam_id}}" data-change-state-url="{{change_state_url}}" style="box-shadow: none">
      {% blocktrans %}
        No, I want to continue working.
      {% endblocktrans %}
    </button>
  {% endif %}
</div>
<script type="text/javascript">
  $('.exam-action-button').click(
    function(event) {

      // cancel any warning messages to end user about leaving timed exam
      $(window).unbind('beforeunload');

      var action_url = $(this).data('change-state-url');
      var exam_id = $(this).data('exam-id');
      var action = $(this).data('action');

      // Update the state of the attempt
      $.ajax({
        url: action_url,
        type: 'PUT',
        data: {
          action: action
        },
        success: function() {
          // Reloading page will reflect the new state of the attempt
          location.reload();
        }
      });
    }
  );
</script>
