<div class="np-training-session-cta">
  <div class="overview-cta-btn-container">
    <form
      action="{{ training_session.cta.url }}"
      method="post"
    >
      {% form_authenticity_token %}

      {% if training_session.show_calendar_links? %}
        {% include "training_session_calendars" %}
      {% endif %}

      {% if training_session.cta.undo? %}
        <input type="hidden" name="_method" value="delete" />
      {% endif %}

      {% if training_session.cta.label %}
        <button
          id="register-btn"
          type="submit"
          class="overview-cta-btn"
          onclick="redirectToSessionUrl()"
        >
          {{ training_session.cta.label }}
        </button>
      {% endif %}
    </form>
  </div>
</div>

<script>
  function redirectToSessionUrl() {
      const registerBtn = document.getElementById('register-btn');
      const sessionUrl = '{{training_session.session_url}}';

      if (registerBtn.innerText == 'Register') {
        window.open(sessionUrl, '_blank').focus();
      }
  }
</script>
