<?php use App\Core\View; ?>
<header class="page-head">
  <h1>Enquiries</h1>
  <p>Messages from the website contact form.</p>
</header>

<div class="panel">
  <table class="table">
    <thead>
      <tr><th>Received</th><th>Name</th><th>Contact</th><th>Message</th><th>Status</th><th class="actions">Actions</th></tr>
    </thead>
    <tbody>
      <?php if (!$rows): ?>
      <tr><td colspan="6" class="empty">No enquiries yet.</td></tr>
      <?php endif; ?>
      <?php foreach ($rows as $c): ?>
      <tr>
        <td><?= View::e($c['created_at']) ?></td>
        <td><?= View::e($c['name']) ?></td>
        <td>
          <a href="mailto:<?= View::e($c['email']) ?>"><?= View::e($c['email']) ?></a>
          <?php if ($c['phone']): ?><br><?= View::e($c['phone']) ?><?php endif; ?>
        </td>
        <td class="wrap-text"><?= nl2br(View::e($c['message'])) ?></td>
        <td><span class="badge <?= $c['handled'] ? 'ok' : '' ?>"><?= $c['handled'] ? 'Handled' : 'New' ?></span></td>
        <td class="actions">
          <form method="post" action="<?= View::url('/admin/contacts/' . (int) $c['id'] . '/toggle') ?>">
            <input type="hidden" name="_csrf" value="<?= $csrf ?>">
            <button class="btn sm" type="submit"><?= $c['handled'] ? 'Mark new' : 'Mark handled' ?></button>
          </form>
        </td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
</div>
