<div class="toolbar">
  <div></div>
  <button type="button" class="btn btn-primary" data-modal-open="new-customer">+ New customer</button>
</div>

<div class="modal-overlay" id="new-customer">
  <div class="modal-box">
    <div class="modal-header"><h3>New customer</h3><button type="button" class="modal-close" data-modal-close aria-label="Close">&times;</button></div>
    <div class="modal-body">
      <form method="post" action="<?= url('/admin/customers') ?>">
        <?= csrf_field() ?>
        <div class="form-group"><label>Name <span class="req">*</span></label><input type="text" name="name" required></div>
        <div class="form-row">
          <div class="form-group"><label>Code</label><input type="text" name="code"></div>
          <div class="form-group"><label>Industry</label><input type="text" name="industry"></div>
        </div>
        <button class="btn btn-primary btn-block">Create</button>
      </form>
    </div>
  </div>
</div>

<div class="card">
  <div class="table-wrap">
    <table class="table">
      <thead><tr><th>Customer</th><th>Code</th><th>Industry</th><th>Contacts</th><th>Active contracts</th><th>Status</th><th></th></tr></thead>
      <tbody>
      <?php foreach ($customers as $c) : ?>
        <tr>
          <td><a class="row-link" href="<?= url('/admin/customers/' . $c['id']) ?>"><?= e($c['name']) ?></a></td>
          <td class="text-sm"><?= e($c['code']) ?></td>
          <td class="text-sm"><?= e($c['industry']) ?></td>
          <td><?= (int)$c['contact_count'] ?></td>
          <td><?= (int)$c['contract_count'] ?></td>
          <td><span class="badge <?= $c['is_active'] ? 'badge-resolved' : 'badge-closed' ?>"><?= $c['is_active'] ? 'Active' : 'Inactive' ?></span></td>
          <td><a href="<?= url('/admin/customers/' . $c['id']) ?>" class="btn btn-sm">Edit</a></td>
        </tr>
      <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>
