<div id="debrid-auth-status" class="notification is-info">
  <p>Pour activer votre compte Debrid-Link :</p>
  <p><strong>Code :</strong> {{ .code }}</p>
  <p><strong>URL :</strong> <a href="{{ .url }}" target="_blank">{{ .url }}</a></p>
</div>

<script>
  let attempts = 0;
  const maxAttempts = 10;
  const interval = setInterval(() => {
    attempts++;
    if (attempts > maxAttempts) {
      clearInterval(interval);
      return;
    }

    fetch('/godownloader/poll-status')
      .then(res => res.json())
      .then(data => {
        if (data.success) {
          clearInterval(interval);

          // Cible la notification en attente
          const notifContainer = document.getElementById('debrid-auth-status');
          if (notifContainer) {
            notifContainer.className = 'notification is-success';
            notifContainer.innerHTML = '✅ Compte activé avec succès !';
            setTimeout(() => notifContainer.remove(), 5000);
          }

          // Rafraîchit la table des comptes
          htmx.ajax('GET', '/godownloader/table-refresh', {
            target: '#accounts-table',
            swap: 'outerHTML'
          });
        }
      });
  }, 5000);
</script>
