<?php
session_start();
if (!isset($_SESSION['is_admin']) || $_SESSION['is_admin'] !== true) {
    header("Location: admin-login.php");
    exit();
}

require_once("auth/db.php");

$users = [];
$result = $conn->query("SELECT * FROM archived_users ORDER BY id DESC");
while ($row = $result->fetch_assoc()) {
    $users[] = $row;
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Archived Users - Gobolcoin</title>
  <style>
    body { font-family: Arial; padding:20px; }
    table { width:100%; border-collapse: collapse; }
    th, td { padding:10px; border:1px solid #ddd; }
    th { background:#8B0000; color:#fff; }
  </style>
</head>
<body>
  <h2>Archived Users</h2>
  <table>
    <thead>
      <tr>
        <th>S/N</th>
        <th>Name</th>
        <th>Email</th>
        <th>Country</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <?php $sn=1; foreach($users as $u): ?>
      <tr>
        <td><?= $sn++ ?></td>
        <td><?= htmlspecialchars($u['first_name'].' '.$u['surname']) ?></td>
        <td><?= htmlspecialchars($u['email']) ?></td>
        <td><?= htmlspecialchars($u['country']) ?></td>
        <td>
          <a href="restore-user.php?id=<?= $u['id'] ?>"
             onclick="return confirm('Restore this user back to active users?');">Restore</a>
        </td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
</body>
</html>