<?php
require 'db.php';

$page  = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 15;
$offset = $page * $limit;

$stmt = $pdo->prepare("
   SELECT 
        u.id,
        u.username,
        u.firstname,
        u.secondname,
        u.email,
        u.role,
        u.is_verified FROM users u
        WHERE
         u.is_verified = 0 
    ORDER BY is_verified ASC
    LIMIT :limit OFFSET :offset
");

$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

    
    echo "<tr id='userRow_{$row['id']}'>";
   echo "<td>{$row['username']}</td>";
echo "<td>{$row['firstname']}</td>";
echo "<td>{$row['secondname']}</td>";
echo "<td>{$row['email']}</td>";


echo "<td class='text-end action-cell'>";
if (!$row['is_approved']) {
    echo "<button class='btn btn-sm btn-success'
            onclick='admin_approve_User({$row['id']})'>
            Approve
          </button>";
} else {
    echo "-";
}
echo "</td>";
echo "</tr>";
}
