<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/flash.php';
require_admin();
$id = (int)($_GET['id'] ?? 0);
$row = null;
if ($id > 0) {
    $st = db()->prepare('SELECT * FROM team_members WHERE id = ?');
    $st->execute([$id]);
    $row = $st->fetch();
}
if (!$row) {
    admin_flash_set('danger', 'Not found.');
    header('Location: team.php');
    exit;
}
$page = 'team';
$pageTitle = 'Team member';
$pageSubtitle = (string)$row['name'];
$breadcrumbs = [['label' => 'Dashboard', 'href' => 'index.php'], ['label' => 'Team', 'href' => 'team.php'], ['label' => (string)$row['name'], 'href' => null]];
$headerActions = '<a href="team-edit.php?id=' . (int)$row['id'] . '" class="btn btn-primary btn-sm"><i class="bi bi-pencil me-1"></i>Edit</a><a href="team.php" class="btn btn-outline-secondary btn-sm">Back</a>';
require __DIR__ . '/includes/layout-header.php';
?>
<div class="row g-4">
  <div class="col-md-8">
    <div class="admin-card rounded">
      <div class="card-header">Bio</div>
      <div class="card-body">
        <p class="text-muted mb-1 small text-uppercase fw-semibold"><?= h((string)($row['designation'] ?? '')) ?></p>
        <div class="mb-0"><?= nl2br(h((string)$row['bio'])) ?: '<span class="text-muted">No bio.</span>' ?></div>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="admin-card rounded mb-3">
      <div class="card-header">Photo</div>
      <div class="card-body text-center"><?php if (!empty($row['image_path'])): ?><img src="../<?= h((string)$row['image_path']) ?>" class="img-fluid rounded-circle shadow" style="max-width:200px;" alt=""><?php else: ?><p class="text-muted mb-0">No photo</p><?php endif; ?></div>
    </div>
    <div class="admin-card rounded">
      <div class="card-header">Danger zone</div>
      <div class="card-body">
        <form method="post" action="team.php" onsubmit="return confirm('Delete this member?');">
          <input type="hidden" name="csrf" value="<?= h(csrf_token()) ?>">
          <input type="hidden" name="delete_id" value="<?= (int)$row['id'] ?>">
          <button type="submit" class="btn btn-outline-danger btn-sm w-100">Delete</button>
        </form>
      </div>
    </div>
  </div>
</div>
<?php require __DIR__ . '/includes/layout-footer.php'; ?>
