<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title><%= conf.label %> — Administration IGF Burundi</title>
<%- include('_styles') %>
</head>
<body>
  <div class="topbar">
    <strong>Administration IGF Burundi</strong>
    <form method="POST" action="/admin/logout"><button>Se déconnecter</button></form>
  </div>
  <div class="layout">
    <div class="sidebar">
      <% for (const [group, items] of Object.entries(groups)) { %>
        <h3><%= group %></h3>
        <% items.forEach(function(it) { %>
          <a href="/admin/<%= it.key %>" style="<%= it.key === resourceKey ? 'font-weight:700;color:#e2762a;' : '' %>"><%= it.label %></a>
        <% }); %>
      <% } %>
    </div>
    <div class="main">
      <div class="actions-bar">
        <h1><%= conf.label %></h1>
        <% if (!conf.readOnly) { %>
          <a class="btn" href="/admin/<%= resourceKey %>/new">+ Ajouter</a>
        <% } %>
      </div>
      <table>
        <thead>
          <tr>
            <% conf.listColumns.forEach(function(col) { %><th><%= col %></th><% }); %>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <% items.forEach(function(item) { %>
            <tr>
              <% conf.listColumns.forEach(function(col) { %>
                <td><%= typeof item[col] === 'boolean' ? (item[col] ? '✓' : '—') : (item[col] ?? '') %></td>
              <% }); %>
              <td class="actions">
                <a href="/admin/<%= resourceKey %>/<%= item.id %>/edit">Modifier</a>
                <% if (!conf.readOnly) { %>
                  &nbsp;·&nbsp;
                  <form method="POST" action="/admin/<%= resourceKey %>/<%= item.id %>/delete" onsubmit="return confirm('Supprimer définitivement cet élément ?');">
                    <button type="submit" style="background:none;border:none;color:#c0392b;cursor:pointer;padding:0;font-size:.88rem;">Supprimer</button>
                  </form>
                <% } %>
              </td>
            </tr>
          <% }); %>
          <% if (items.length === 0) { %>
            <tr><td colspan="<%= conf.listColumns.length + 1 %>">Aucun élément pour le moment.</td></tr>
          <% } %>
        </tbody>
      </table>
    </div>
  </div>
</body>
</html>
