<?php
$page_title = 'Team Overview';
require_once __DIR__ . '/header.php';
// Restrict to Managers
if (!in_array($role, ['manager', 'admin', 'super_admin'])) redirect('index.php');

$team = $db->query("SELECT * FROM employees WHERE department='{$dept}' AND id != {$emp_id} ORDER BY name ASC")->fetchAll();
?>

<div class="card">
  <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;">
    <h3 style="margin:0;color:#0f172a;">My Team (<?= h($dept) ?>)</h3>
  </div>
  <div class="table-wrap">
    <table>
      <thead>
        <tr>
          <th>Employee</th>
          <th>ID Code</th>
          <th>Designation</th>
          <th>Status</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($team as $m): ?>
        <tr>
          <td><strong><?= h($m['name']) ?></strong><br><span style="font-size:.85rem;color:#64748b;"><?= h($m['email']) ?></span></td>
          <td><?= h($m['emp_code'] ?: '-') ?></td>
          <td><?= h($m['designation'] ?: 'Staff') ?></td>
          <td><span class="badge badge-<?= $m['status']==='active'?'success':'danger' ?>"><?= h($m['status']) ?></span></td>
          <td><a href="#" style="color:#2557d6;font-size:.85rem;font-weight:600;text-decoration:none;">View Profile</a></td>
        </tr>
        <?php endforeach; ?>
        <?php if(!$team): ?>
        <tr><td colspan="5" style="text-align:center;color:#64748b;padding:20px;">No other team members found in your department.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
</div>

<?php require_once __DIR__ . '/footer.php'; ?>
