<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>Admin - Hosts</title>
    <style>body{font-family:system-ui,Arial;padding:20px} table{width:100%;border-collapse:collapse} th,td{padding:8px;border-bottom:1px solid #eee} .actions a{margin-right:8px}</style>
  </head>
  <body>
    <header style="display:flex;justify-content:space-between;align-items:center">
      <h1>Administration</h1>
      <div><a href="/admin/logout">Logout</a></div>
    </header>

    <section>
      <p><a href="/admin/new">Créer un nouvel hôte</a> · <form style="display:inline" method="post" action="/admin/reload"><button type="submit">Reload OIDC</button></form></p>
      <table>
        <thead><tr><th>ID</th><th>Prefix</th><th>Upstream</th><th>OIDC</th><th>Masked</th><th>Actions</th></tr></thead>
        <tbody>
          <% hosts.forEach(function(h){ %>
            <tr>
              <td><%= h.id %></td>
              <td><%= h.pathPrefix %></td>
              <td><%= h.upstream %></td>
              <td><%= h.oidc ? 'yes' : 'no' %></td>
              <td><%= h.maskUpstream ? 'yes' : 'no' %></td>
              <td class="actions">
                <a href="/admin/edit/<%= h.id %>">Edit</a>
                <a href="/admin/preview/<%= h.id %>" target="_blank">Preview</a>
                <form method="post" action="/admin/delete/<%= h.id %>" style="display:inline" onsubmit="return confirm('Supprimer ?');">
                  <button type="submit">Delete</button>
                </form>
              </td>
            </tr>
          <% }) %>
        </tbody>
      </table>
    </section>
  </body>
</html>
