<?php require_once __DIR__ . '/includes/admin_bootstrap.php';
ugfx_require_permission('applications');
$adminTitle='Applications';
$items = array_reverse(ugfx_read_json($ugfx['storage']['applications'], []));
include __DIR__ . '/includes/admin_header.php'; ?>
<div class="ugfx-card p-4">
  <div class="ugfx-admin-toolbar"><div><div class="ugfx-micro-label">FRONT PAGE MATCH</div><h3 class="mb-0">Join the Team applications</h3></div><span class="ugfx-chip">join.php</span></div>
  <div class="table-responsive mt-3">
    <table class="table ugfx-table ugfx-admin-table align-middle">
      <thead>
        <tr><th>Name</th><th>Email</th><th>Role</th><th>Availability</th><th>Attachment</th><th>Status</th><th>Submitted</th></tr>
      </thead>
      <tbody>
        <?php foreach ($items as $item): ?>
          <tr>
            <td><?= htmlspecialchars($item['name'] ?? '') ?></td>
            <td><?= htmlspecialchars($item['email'] ?? '') ?></td>
            <td><?= htmlspecialchars($item['role'] ?? '') ?></td>
            <td><?= htmlspecialchars($item['availability'] ?? '') ?></td>
            <td><?php if (!empty($item['attachment']['path'])): ?><a href="../<?= htmlspecialchars($item['attachment']['path']) ?>" target="_blank" rel="noopener"><?= htmlspecialchars($item['attachment']['name'] ?? 'Open file') ?></a><?php else: ?><span class="text-secondary">—</span><?php endif; ?></td>
            <td><span class="ugfx-chip"><?= htmlspecialchars($item['status'] ?? 'new') ?></span></td>
            <td><?= htmlspecialchars($item['created_at'] ?? '') ?></td>
          </tr>
          <tr class="ugfx-admin-subrow">
            <td colspan="7" class="small">
              <?= nl2br(htmlspecialchars($item['experience'] ?? '')) ?>
              <?php if (!empty($item['links'])): ?><div class="mt-2">Links: <?= nl2br(htmlspecialchars($item['links'])) ?></div><?php endif; ?>
            </td>
          </tr>
        <?php endforeach; ?>
        <?php if (!$items): ?>
          <tr><td colspan="7" class="text-center py-4"><div class="ugfx-admin-empty-state">No applications submitted yet.</div></td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
<?php include __DIR__ . '/includes/admin_footer.php'; ?>