<?php
$active = 'home';
$pageTitle = 'Employee Onboarding';
require __DIR__ . '/../layout/workspace_header.php';
?>
<div class="topbar">
  <div>
    <h1>Employee Onboarding</h1>
    <div class="crumbs"><a href="/workspace" style="color:var(--blue-600);">Workspace</a> → Employee Onboarding</div>
  </div>
  <div class="user-chip"><span class="dot"></span> <?= htmlspecialchars($user['name']) ?></div>
</div>

<?php if (!empty($notifications)): ?>
  <?php foreach ($notifications as $n): ?>
    <div class="alert alert-success" style="display:flex;justify-content:space-between;align-items:center;">
      <span><?= htmlspecialchars($n['title']) ?> — <?= htmlspecialchars($n['message']) ?></span>
      <a href="/onboarding?read_notif=<?= (int)$n['id'] ?>" style="color:var(--blue-600);font-weight:600;">Open →</a>
    </div>
  <?php endforeach; ?>
<?php endif; ?>

<div style="display:grid;grid-template-columns:repeat(7,1fr);gap:10px;margin-bottom:16px;">
  <?php
  $labels = ['New'=>'New','A_sent'=>'Phase A sent','A_done'=>'I-9 due','I9_done'=>'I-9 verified','Training'=>'Training done','B_sent'=>'Phase B sent','Final'=>'Finalized'];
  foreach ($labels as $key => $label): ?>
    <div class="card" style="margin-bottom:0;text-align:center;">
      <div style="font-size:22px;font-weight:800;"><?= (int)($counts[$key] ?? 0) ?></div>
      <div style="font-size:11px;color:var(--text-muted);text-transform:uppercase;"><?= htmlspecialchars($label) ?></div>
    </div>
  <?php endforeach; ?>
</div>

<div class="card">
  <div class="toolbar">
    <div></div>
    <a href="/onboarding/new" class="btn-primary" style="text-decoration:none;">+ New Hire</a>
  </div>
  <table>
    <thead><tr><th>Name</th><th>Site</th><th>Hire Date</th><th>Status</th><th></th></tr></thead>
    <tbody>
      <?php foreach ($hires as $h): ?>
        <tr>
          <td style="font-weight:700;"><?= htmlspecialchars(onb_full_name($h)) ?>
            <div style="color:var(--text-muted);font-size:12px;font-weight:400;"><?= htmlspecialchars($h['position'] ?? '') ?> · <?= htmlspecialchars($h['email'] ?? '') ?></div>
          </td>
          <td><?= htmlspecialchars($h['site'] ?? '') ?></td>
          <td><?= onb_fmt_mdy($h['hire_date']) ?></td>
          <td><span class="badge badge-manager"><?= htmlspecialchars(onb_status_label($h['status'])) ?></span></td>
          <td><a href="/onboarding/view?id=<?= (int)$h['id'] ?>" class="btn-secondary" style="text-decoration:none;padding:6px 12px;font-size:12px;">Open</a></td>
        </tr>
      <?php endforeach; ?>
      <?php if (empty($hires)): ?>
        <tr><td colspan="5" style="text-align:center;color:var(--text-muted);padding:24px;">No hires yet — click "+ New Hire" to start.</td></tr>
      <?php endif; ?>
    </tbody>
  </table>
</div>

<?php require __DIR__ . '/../layout/admin_footer.php'; ?>
