<h1>Paramètres Debrid-Link</h1>

<form hx-post="/godownloader/settings" hx-target="#auth-status" hx-swap="innerHTML">
  <input type="text" name="username" placeholder="Email" required>
  <input type="password" name="password" placeholder="Mot de passe" required>
  <button type="submit">Se connecter</button>
</form>
<div id="auth-status"></div>


<h2 class="title is-4">Comptes enregistrés</h2>

<div id="accounts-table">
{{ if .accounts }}
  <table class="table is-striped is-fullwidth">
    <thead>
      <tr>
        <th>Host</th>
        <th>Utilisateur</th>
        <th>Actif</th>
        <th>Token</th>
        <th>Expire</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      {{ range .accounts }}
      <tr>
        <td>{{ .Host }}</td>
        <td>{{ .Username }}</td>
        <td>{{ if .IsActive }}✅{{ else }}❌{{ end }}</td>
        <td><code>{{ .AccessToken | printf "%.12s..." }}</code></td>
        <td>{{ .ExpiresAt.Format "02/01/2006 15:04" }}</td>
        <td>
         <div class="buttons">
            <a class="button is-danger is-light"
               hx-get="/godownloader/settings/delete?id={{ .ID }}"
               hx-target="#accounts-table"
               hx-swap="outerHTML">Supprimer</a>
            <a class="button is-info is-light"
               hx-get="/godownloader/settings/toggle?id={{ .ID }}"
               hx-target="#accounts-table"
               hx-swap="outerHTML">
              {{ if .IsActive }}Désactiver{{ else }}Activer{{ end }}
            </a>
          </div>
        </td>
      </tr>
      {{ end }}
    </tbody>
  </table>
{{ else }}
  <p>Aucun compte enregistré.</p>
{{ end }}
</div>
