<?php /** @var array $list; @var string $status */ ?>
<div class="p-8">
  <div class="flex items-start justify-between">
    <div>
      <div class="text-xs uppercase tracking-[0.3em] text-gold"><?= e(t('hub.forms.kicker')) ?></div>
      <h1 class="mt-2 text-3xl font-display"><?= e(t('hub.forms.title')) ?></h1>
    </div>
    <a href="<?= url('/hub/forms/new') ?>" class="btn-gold"><?= e(t('hub.forms.new')) ?></a>
  </div>

  <div class="mt-6 flex gap-2">
    <a href="<?= url('/hub/forms') ?>" class="chip <?= !$status ? 'chip-active' : '' ?>"><?= e(t('common.all')) ?></a>
    <?php foreach (['DRAFT','SUBMITTED','SIGNED'] as $s): ?>
      <a href="<?= url('/hub/forms?status=' . $s) ?>" class="chip <?= $status === $s ? 'chip-active' : '' ?>"><?= e($s) ?></a>
    <?php endforeach; ?>
  </div>

  <div class="mt-6 bg-ink/40 border border-white/10 rounded-xl overflow-hidden">
    <?php if (empty($list)): ?>
      <div class="p-12 text-center text-bone/40"><?= e(t('hub.forms.empty')) ?></div>
    <?php else: ?>
      <table class="w-full text-sm">
        <thead class="bg-white/5 text-xs uppercase tracking-widest text-bone/50">
          <tr>
            <th class="text-left px-5 py-3"><?= e(t('hub.table.customer')) ?></th>
            <th class="text-left px-5 py-3"><?= e(t('form.status')) ?></th>
            <th class="text-left px-5 py-3"><?= e(t('form.updated')) ?></th>
            <th class="text-right px-5 py-3"></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($list as $f):
            $cust = !empty($f['customer_id']) ? \App\Repositories\Container::users()->find($f['customer_id']) : null;
            $name = $cust ? trim(($cust['first_name'] ?? '') . ' ' . ($cust['last_name'] ?? '')) : ($f['general_info']['first_name'] ?? '') . ' ' . ($f['general_info']['last_name'] ?? '');
          ?>
            <tr class="border-t border-white/5 hover:bg-white/5">
              <td class="px-5 py-3"><?= e(trim($name) ?: '—') ?></td>
              <td class="px-5 py-3"><span class="pill pill-<?= e(strtolower($f['status'] ?? 'draft')) ?>"><?= e($f['status'] ?? '') ?></span></td>
              <td class="px-5 py-3 text-bone/60 text-xs"><?= e($f['updated_at'] ?? '') ?></td>
              <td class="px-5 py-3 text-right"><a class="text-gold hover:underline text-xs" href="<?= url('/hub/forms/' . e($f['id'])) ?>"><?= e(t('common.open')) ?> →</a></td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
