<div class="np-training-session-cta-note np-training-session-tile-badge np-training-session-tile-badge-{{ training_session.status.type }}">
    {% if training_session.approved? %}
        <i class="far fa-check np-training-session-icon"></i>
    {% endif %}
    {{ training_session.status.label }}
</div>

<script>
    document.addEventListener("DOMContentLoaded", () => {
  const btn = document.querySelector('.np-training-session-cta-note');

  if (btn) {
    const eventId = btn.getAttribute('data-event-id');
    const statusKey = `eventStatus-${eventId}`;
    const maxAttempts = 15;
    let attempts = parseInt(sessionStorage.getItem(statusKey)) || 0;


    if (btn.innerText.trim() === 'PENDING - WAITING APPROVAL' && attempts < maxAttempts) {
      setTimeout(() => {
        attempts++;
        sessionStorage.setItem(statusKey, attempts);
        window.location.reload();
      }, 2000);
    }


    if (btn.innerText.trim() !== 'PENDING - WAITING APPROVAL') {
      sessionStorage.removeItem(statusKey);
    }
  }
});
</script>
