<%- include('partials/header') %>

<h1>Tableau de bord</h1>

<div class="cards">
  <div class="card"><div class="num"><%= nbBiens %></div><div class="lbl">Biens en ligne</div></div>
  <div class="card"><div class="num"><%= nbMessages %></div><div class="lbl">Demandes reçues</div></div>
  <div class="card<%= nonLus > 0 ? ' alert' : '' %>"><div class="num"><%= nonLus %></div><div class="lbl">Non lues</div></div>
  <div class="card"><div class="num"><%= typeof nbAvantages !== 'undefined' ? nbAvantages : 0 %></div><div class="lbl">Avantages</div></div>
</div>

<div class="head-row">
  <h2>Dernières demandes</h2>
  <a class="link" href="/admin/messages">Tout voir →</a>
</div>

<% if (recents.length === 0) { %>
  <p class="muted">Aucune demande pour l'instant.</p>
<% } else { %>
  <table>
    <thead><tr><th>Date</th><th>Nom</th><th>Email</th><th>Message</th></tr></thead>
    <tbody>
      <% recents.forEach(m => { %>
        <tr>
          <td class="nowrap"><%= m.created_at %></td>
          <td><%= m.nom %></td>
          <td><a href="mailto:<%= m.email %>"><%= m.email %></a></td>
          <td><%= (m.message || '').slice(0, 90) %><%= (m.message || '').length > 90 ? '…' : '' %></td>
        </tr>
      <% }) %>
    </tbody>
  </table>
<% } %>

<%- include('partials/footer') %>
